Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Threads are mysteriously dying. 1

Status
Not open for further replies.

mheppler

Programmer
Feb 6, 2006
8
0
0
US
I have a multithread application: a Master and several Workers. They each have a while(true) loop to do their thing.
The Master enqueues an integer in a shared queue. The Worker dequeues an integer if there is one there. I use Thread.Sleep(1) in the Master as a loop governor. I use a ManualResetEvent workToDoEvent for the workers to check and block on: "if (workToDoEvent(10, false)" -- the 10ms being the Worker's loop governor. After a period of enqueueing and dequeueing my Workeres seem to dissapear without a trace -- no exceptions and no output to the common ListBox(where I display what is happening). I'm clueless. Thanks, Mark
 
Do you have an unhandled-exception handler set up? If your worker threads are throwing an exception, it would (most likely) end up here, and you can then find & fix the problem.
Code:
public static void Main(string[] args)
{
  AppDomain currentDomain = AppDomain.CurrentDomain;
  currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UEHandler);

  // Run app here
}

// un-caught Exception handler
private static void UEHandler(object sender, UnhandledExceptionEventArgs args)
{
  Exception ex = args.ExceptionObject as Exception;
  if (ex != null)
  {
    Console.WriteLine(ex.Message);
  }
}

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top