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.
 
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?
 
Back
Top