Invoke, threads, and exceptions

C

Chris Soulsby

If an exception is raised in a non-main thread then it is not handled.
To get around this I created method that would use the invoke method
on the main form to raise this exception on the main thread. For
example:

this.Invoke(new InvokeDelegate(this.ThreadExceptionHandler),new
object[]{o});

However, this still does not seem to work correctly as I still get an
unhandled exception. It does not fall back to the main() function
where my catch all code is. Can anyone tell me whats going on?

Thanks for any help.

Chris
 
J

Jochen Kalmbach

Chris said:
If an exception is raised in a non-main thread then it is not handled.
To get around this I created method that would use the invoke method
on the main form to raise this exception on the main thread.

Why not use:
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(...);


--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
 
D

Dan Cimpoiesu

Try this:
-Put all thread code in a big try catch
-On the catch branch raise an user define event or invoke SendMessage API
-After this you can handle the event in the main App (if you send an message
override the WndProc and catch it)

Hope this helps

Dan Cimpoiesu
 

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