0

Is there a way to catch a terminating thread in C# at the deepest level? I currently have:

AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(App_ThreadException);

at the start

~IOThread()
{
    Console.WriteLine(string.Format("IOThread destroyed at: {0}", DateTime.Now));
}

A destructor.

a

try
{
    Server.world.Tick();
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
}

try catch for a failed access or null ref. Yet still! Something is causing the processing thread to stop, and its not an infinite loop because if I do BreakAll in the debugger the processing thread is not in the threads list.

Any help would be greatly appreciated, I cannot even debug this issue.

Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124
Vans S
  • 1,743
  • 3
  • 21
  • 36
  • 1
    please write the question with patience , some buddy need to understand what the problem is? Please re-phrase it. – TalentTuner Mar 12 '13 at 04:50
  • I don't see the misunderstanding? What are some ways to catch regular terminating threads run with (new Thread(IOThread.run)).Start(); – Vans S Mar 12 '13 at 04:52
  • You should post the full code of thread's delegate (IOThread.run). – Nikita B Mar 12 '13 at 05:17

2 Answers2

0

First of all AppDomain.CurrentDomain.UnhandledException does not "catch" anything. Your application will still crash if there is an exception. This event is there so you can do some stuff before the crash.

Second, you are confusing destructors with finalizers.

Third, if there is an unhandled exception in another thread - the whole application will crash. If it doesnt crash - that can only mean one thing - your thread simply finished working.

Nikita B
  • 3,303
  • 1
  • 23
  • 41
0

The only way to do this properly is to put catch(Exception) at the root of every thread you create in your program, including thread pool callback methods.

user626528
  • 13,999
  • 30
  • 78
  • 146