Exception handling in threads

S

stormogulen

Hi all,

Just a quck question about exception handling in threads:

If an exception occurs in a thread that I have created myself, the
whole application crashes. How do I best handle these exception, and
push them back to the main thread?

I have seen solutions that wrap the Thread class in a SafeThread
class, which has an event that is raised in case of an exception. I
would like to force the implementer to handle this event, so would a
callback in the constructor be a better solution?

I'm also considering using a static event on my Thread class instead
of an event on each instance. Can anybody tell me the drawbacks of
static events?

Best regards
Bjarne
 
G

Gaston Hillar

You can check my article in Packt's website:
http://www.packtpub.com/article/simplifying-parallelism-complexity-c-sha
rp
You can also download code examples from my book "C# 2008 and 2005
threaded programming", in
http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-thread
ed-programming

In this book, you will find many topics related to exception handling in
threads. They'll be very usuful for you to solve your problem. Catching
exceptions in threads is one of the most difficult things to learn when
programming using many concurrent threads. I would need some diagrams to
explain you that. The book will do it for me :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top