Catch Exception in background thread

  • Thread starter Thread starter Guest
  • Start date Start date
Jesper,

What I would do is create a delegate that takes an exception as a
parameter. Then, define a method with the same signature on your form.
From the thread, when the exception is caught, call the Invoke method on the
control, passing the delegate with the method, and the exception. Then, the
method will be called on the main UI thread, at which point, you can show
the details of the exception.

Hope this helps.
 
AppDomain has an UnhandledException
Application has a ThreadException
 
Thank you very much, it helped alot.


Nicholas Paldino said:
Jesper,

What I would do is create a delegate that takes an exception as a
parameter. Then, define a method with the same signature on your form.
From the thread, when the exception is caught, call the Invoke method on the
control, passing the delegate with the method, and the exception. Then, the
method will be called on the main UI thread, at which point, you can show
the details of the exception.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jesper Nilsson said:
I'm using a background thread in my application with this example:
http://www.codeproject.com/csharp/winformthreading.asp

Do you guys know any easy way to catch exceptions being thrown in the
background thread and show error on the mainForm?
 

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

Back
Top