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?