473,399 Members | 2,774 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,399 software developers and data experts.

Exception in a Thread other than Main thread

Hi,
I have one program, where i am using IO and Socket Asynchronous methods
"BeginXXX" and "EndXXX".

Many time, it happens that in Async delegate method, some exception occurs
and if i dont handle it, it shows standard Unhandled exception box even I
have handled the exception using try/catch in the main thread which is
caller of that method.
That means, the exception cant be handled by catch block written in main
thread if the exception occurs in a thread other than main.

My intention is to get the exception message so i can handle it gracefully
and show a userfriendly message on that exception. So usual, i use re-throw
the exceptions and handle in main UI blocks, if its not possible to return
values or if return value is possible then as return value so in UI blocks i
can show user friendly messages.

But as mentioned above, in multi-threaded program, if such condition happens
then what is the solution?
Is it possible to do that anyhow?
Is it by design or my program has bad-design?
If this is bad design then please suggest better way,

Thanking you in Advance,
Regards,
Mahesh
May 18 '06 #1
2 1483
Use

Application.ThreadException+=new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);

Tasos.

May 18 '06 #2
Hi,
Thanks for the kool pointer.
But the problem is we have many of independent components and some of
components internally uses other components and now inner most component
class has thrown some exception in different thread [other than main thread]
then will it be caught in Main thread in Main application?
e.g.
Main App [with UI] -> Comp1 -> Comp2 -> Comp3
Now if Comp3 throws an exception in diff thread then ThreadException will
catch that exception but what if i want to catch it in Comp1 or Comp2 where
i havnt not used UI [means Windows Forms] ?
This ThreadException event force me to use Windows.Forms assemly so is there
any other similar way?
Also, this is a single event method where i am getting this exception but if
i want to catch exception by caller and it may be any seperate methods so is
it possible to catch this exception in caller method somehow? because its
tough to handle all the exception in one method and who throws that
exception, how we can know if its really hugh application with lots of
components?

Else this will be definately helpful to me.

Thanks,
Mahesh
"Tasos Vogiatzoglou" <tv*****@gmail.com> wrote in message
news:11********************@38g2000cwa.googlegroup s.com...
Use

Application.ThreadException+=new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);

Tasos.

May 19 '06 #3

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

Similar topics

1
by: pegazik | last post by:
Hello. I have problem and I'm looking for help. Probably there is some quite easy solution, but I can't see it. I'm trying to perform some action that have to be timeout safe. So here is the...
5
by: Hao L | last post by:
For example, void WorkerMethod() { ... UnregisterAllHotkeys();} void UnregisterAllHotKeys { for(...) {UnregisterHotKey(...);}} UnregisterHotKey is an API function that must be on the thread...
7
by: Edwin | last post by:
Hello, I would like the Main()-thread to end (because it runs out of the code), but all started threads should continue. Is this possible. Eg. static void Main(string args) {
4
by: Charles Law | last post by:
Hi guys. I have two threads: a main thread and a background thread. Lots of stuff happens in the background thread that means I have to update several (lots) of controls on a form. It is...
3
by: Franck | last post by:
Hi, Got a windows Service which run under LOCAL SYSTEM account. Its main goal is to printout xls file to pdf. It seems that LOCAL SYSTEM account has not enough rights to do that (as launching...
2
by: Tim | last post by:
The are 2 threads - main thread and worker thread. The main thread creates the worker thread and then the worker thread runs in an infinite while loop till it is asked to exit by setting an event....
2
by: Mahesh Devjibhai Dhola | last post by:
Hi, I have one program, where i am using IO and Socket Asynchronous methods "BeginXXX" and "EndXXX". Many time, it happens that in Async delegate method, some exception occurs and if i dont...
4
by: ipramod | last post by:
Hi, I am having an application which inserts some data into a table. While inserting table rows, I want to check CPU percentage and if it is >90% then I want to sleep insertion for some time and...
1
by: ASPnewb1 | last post by:
Hello. I've developed an application that reads at a constant fast rate, bytes from a serial port, and posts these to a textbox on the main form. Basically a serial port monitor of sorts...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.