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?
SingleOrDefault()on your original query and do some stuff? This doesn't make sense at all... For starters, why do you run the same query twice? And secondly, if you enter your first if-statement, you'll never enter the second one... And what ifmatchedprod.Count()is >2? And you delete only one item? So many questions...