One thing I'm struggling to understand with C# threading..
Is that a child thread throwing an exception causes the entire application to fail.. Why does it not just kill the child thread and allow the main thread to carry on living?
Is there any way the parent thread can start the child and make itself immune to exceptions from the child?
Re: One thing I'm struggling to understand with C# threading..
As far I Know a child thread throws an AbortException if something going wrong and the thread is killed. So maybe it helps if your application catches the AbortException and it should be stable.
Another possibility is to use the ThreadPool.QueueUserWorkItem() method for starting the child thread. I think there will be no return from the child thread through an exception.
Re: One thing I'm struggling to understand with C# threading..
I'lll take a look at the threadpool..
.. for now suppose we have the code:
Code:
class Worker{
public void DoWork(){
throw new Exception();
}
}
and we start it like:
Code:
Thread t = new Thread(new ThreadStart(workerInstance.DoWork));
t.Start();
Where would you put the handling code in this?
Re: One thing I'm struggling to understand with C# threading..
Using ThreadPool, the application still exits when the child thread bombs out..
Re: One thing I'm struggling to understand with C# threading..
cjard,
The following link might help you on how to handle the UnHandled exception (occurs in other part of your program including threads).
http://msdn2.microsoft.com/en-us/lib...exception.aspx