Hi
I think we have two points to clarify.
1. common the spawned thread throw unhandled the exception the spawned
thread will terminated, but it will not crash the main applicaiton.
You will find that even if we did not do any thing with the exception
thrown in ThreadProc, the Main Thread is still alive.
static void ThreadProc()
{
Console.WriteLine("Enter Thread");
throw new Exception("Thread Exception");
}
[STAThread]
static void Main(string[] args)
{
//AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Thread th = new Thread(new ThreadStart(ThreadProc));
th.Start();
for(int i=0;i<10;i++)
{
Console.WriteLine("Main Thread alive...");
Thread.Sleep(3000);
}
}
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
Console.WriteLine("Enter unhandled Exception");
Console.WriteLine(e.ExceptionObject.ToString());
}
2. In OS Thread design, all the code is running by thread. All the
exception/Call stack is based on certain detailed thread, one thread can
not catch the exception on another thread.
So for your scenario, you may try to put try...catch inside your threadproc.
static void ThreadProc()
{
try
{
Console.WriteLine("Enter Thread");
throw new Exception("Thread Exception");
}
catch{}
}
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.