|
-
February 16th, 2007, 07:58 AM
#1
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?
-
February 16th, 2007, 08:05 AM
#2
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.
Useful or not? Rate my posting. Thanks.
-
February 16th, 2007, 11:07 AM
#3
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?
-
February 16th, 2007, 11:18 AM
#4
Re: One thing I'm struggling to understand with C# threading..
Using ThreadPool, the application still exits when the child thread bombs out..
-
February 16th, 2007, 11:48 AM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|