The problem is that the program throws an exception. After creating multiple threads. How can we limit the number of threads to be created in the loop?
for (int jrCnt = rCnt; jrCnt <= arrayTable.GetUpperBound(0); jrCnt++)
{
/* bla bla bla */
if ((!string.IsNullOrEmpty(prcI.name)) &&
(prcI.prc != 0))
{
/*bla bla bla*/
var thread = // run updade or add
new Thread(() =>
{
if (!Accessor.AddProductUpdateProduct(prcI)) _updateCounter++;
_countadd++;
});
thread.Name = "Add_or_update-no_" + thread.ManagedThreadId;
thread.Priority = ThreadPriority.Lowest;
thread.Start();
}
Some clarification.
Here is the loop starts top n number of times. Once I add Threadpool this loop is very fast. Therefore Threadpool triggered 180 times. I apologize for my English.
for (int i = sbook; i < book; i++)
{
dt = Accessor.ImporterXls(_path, i);// array for method
ConstructWithBook(dt, rCnt, sbook, book, priceSelect, nametov, pricetov,
categorytov);
}