Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:07:28+00:00 2026-05-28T00:07:28+00:00

With this code vozhus very much in it for a long time tinkering that

  • 0

With this code vozhus very much in it for a long time tinkering that he worked steadily and rapidly. But can not seem to speed it up. Is slow …

for (int jrCnt = rCnt; jrCnt <= arrayTable.GetUpperBound(0); jrCnt++)
{
    var prcI = new Price();

    /* here is the code search and add data to prcI */

    if ((!string.IsNullOrEmpty(prcI.name)) && (prcI.prc != 0))
    { // function add

        /* adding more information to prcI */

        ThreadPool.QueueUserWorkItem(delegate
        {
            if (!Accessor.AddProductUpdateProduct(prcI)) _updateCounter++;
            _countadd++;
        }); // I put the longest function in the streams
    }
}

Here we call the function. It runs for a long time, even with the threadpool.

public static bool AddProductUpdateProduct(Price price)
{
   using (var db = new PriceDataContext())
        {
            var matchedprod =
                db.Price.Where(x => x.name == price.name && x.company == price.company && x.date != price.date);

            if (matchedprod.Select(x=>x).Count() > 1)
            {
                db.Price.DeleteOnSubmit(matchedprod.First());
                db.SubmitChanges();
            }

            var matchedproduct = matchedprod.SingleOrDefault();

            if (matchedproduct != null)
            {
                matchedproduct.date = price.date;
                matchedproduct.prc = price.prc;

                db.SubmitChanges();
                return false;
            }
        }


/*here the code to add the product to the database.*/
return true;
}

Please tell me how to speed up the work with the threadpool?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:07:29+00:00Added an answer on May 28, 2026 at 12:07 am

    Using a separate thread doesn’t speed anything app. All you do is to move the processing from the primary thread to another one. You need to break the processing into smaller parts and move each part to a separate thread to get any performance gain.

    However, it will not help in this case. It’s your LINQ queries that are flawed. Enable debugging. Look at the generated SQL and fix them.

    Secondly:

    if (matchedprod.SingleOrDefault() != null)
    {
        matchedprod.SingleOrDefault().date = price.date;
        matchedprod.SingleOrDefault().prc = price.prc;
    
        db.SubmitChanges();
        return false;
    }
    

    That will query the database three times. Once per call to SingleOrDefault. Do one query and store the result in a variable.

    Third:

    What’s the difference between matchedprod and matchedprodDel? The queries for them are equal?

    Forth:

    This is easier to read:

    var matchedprod = db.Price.Where(x => x.name == price.name && x.company == price.company && x.date != price.date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code compiles in CodeGear 2009 and Visual Studio 2010 but not gcc. Why?
This code works well in Mac/Linux, but not in Windows. import mmap import os
This code should works, but in fact the span is not displayed : <a
This code works in IDLE but not in the commandline. Why the difference? poem
This code compiles fine without warnings but the substring does not appear in the
This code does not seem to compile, I just need to write something to
This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
This code does not write anything to the console cause the collection is empty.
This code here does not work when I try to find a single parent
This code gets the text that's in a certain column of a table row:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.