473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Catch Exception in background thread

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?
Nov 16 '05 #1
3 8911
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]
- mv*@spam.guard.caspershouse.com

"Jesper Nilsson" <Je***********@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
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?

Nov 16 '05 #2
AppDomain has an UnhandledException
Application has a ThreadException
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Jesper Nilsson" <Je***********@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
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?

Nov 16 '05 #3
Thank you very much, it helped alot.
"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Jesper Nilsson" <Je***********@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
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?


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
5
by: Simon Johnson | last post by:
Recently, a thread appeared which asked how to create a "catch all" method for when an exception occurs within a program. The solution given only works for Windows Forms applications, as far as i...
5
by: David | last post by:
I am having a bit of a problem with catching an exception within a thread. Here is the scenario: I have a Windows Form. I create a new thread. This new thread calls a method in another DLL...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
4
by: frog | last post by:
Hi, all: I tried to call Server.Execute in Application_Start and got exception. Any help is appreciated You might ask why I want to do that in the first place. Well, I need to start a...
5
by: Simon Tamman {Uchiha Jax} | last post by:
Now this is bugging me. I just released software for a client and they have reported an unhandled stack overflow exception. My first concern is that the entirity of the UI and any threaded...
3
by: Nick | last post by:
Hi there, This probably wont make much sense but I'm getting an unhandled exception being thrown in the following line... Try While True Redraw control as necessary End While Catch ex as...
16
by: Chuck Cobb | last post by:
I'm implementing a centralized exception handling routine using the Enterprise Library Exception Management Application Block. I trap all unhandled exceptions to one place using the following...
3
by: yeye.yang | last post by:
hey everybody Does everybody can help me or give me some advise for the cross thread exception catch Here is what I want to do: I have 2 classes "Scenario" and "Step", which have a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.