Search code examples
c#multithreading64-bitkernelmulticore

Multi thread .NET application causes Application Error in KERNEL32.dll running on 64 bit quad core Windows Server


I have a multi-threaded .NET application that occasionally terminates without any message. When I check the log there is an entry for an "Application Error in KERNEL32.dll". What could be causing this? Here is some basic code:

foreach (int id in ids)
{
   ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessData), id);
}

The ProcessData method looks like this:

private void ProcessData(object _id)
//Load some data from a database with id = _id
//Process that data and push it to another server using HTTP
//Increment a counter

Interlocked.Increment(ref counter);

//Update progress bar
try
{
  // Invoke the delegate on the form.
  this.Invoke(new BarDelegate(UpdateBar), counter);
}
catch {}
}

There can be millions of ids to process in some cases. But just testing with 10,000 ids usually causes the Application Error described. Am I going about this correctly?

Thank you for any help!


Solution

  • Does QueueUserWorkItem always return true?

    Also, do you get any exceptions in that empty catch?