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

Thread exception

How can I make to route the exceptions from a thread created by my
Application, different that the Applications thread to the application.
I want that when a exception occures in that thread, the application to be
aware of it and to display that default dialog for exceptions.

Regards
Dan Cimpoiesu
Nov 15 '05 #1
5 2101
Dan,

What you would have to do is wrap your thread code in an exception
handler. Once you do that, you will have to send a message to the main
thread (a Windows message) with the exception information. You can do this
by using the GCHandle structure. With it you can allocate a handle to an
object (the exception) and then pass it through a call to SendMessage
(through the P/Invoke layer). Then, in your main form, you can process the
message (assuming you send using a custom message type, usuall WM_USER +
some number) getting the object back through the static methods on the
GCHandle structure.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:uI****************@tk2msftngp13.phx.gbl...
How can I make to route the exceptions from a thread created by my
Application, different that the Applications thread to the application.
I want that when a exception occures in that thread, the application to be
aware of it and to display that default dialog for exceptions.

Regards
Dan Cimpoiesu

Nov 15 '05 #2
Thanks
The part with sending a message I knew it.

I assume that I have to put all my thread code in a big try catch, and when
I catch something to send it to the main app.
Is this correct?

Regards
Dan Cimpoiesu

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:e3**************@TK2MSFTNGP10.phx.gbl...
Dan,

What you would have to do is wrap your thread code in an exception
handler. Once you do that, you will have to send a message to the main
thread (a Windows message) with the exception information. You can do this by using the GCHandle structure. With it you can allocate a handle to an
object (the exception) and then pass it through a call to SendMessage
(through the P/Invoke layer). Then, in your main form, you can process the message (assuming you send using a custom message type, usuall WM_USER +
some number) getting the object back through the static methods on the
GCHandle structure.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:uI****************@tk2msftngp13.phx.gbl...
How can I make to route the exceptions from a thread created by my
Application, different that the Applications thread to the application.
I want that when a exception occures in that thread, the application to be aware of it and to display that default dialog for exceptions.

Regards
Dan Cimpoiesu


Nov 15 '05 #3
Dan,

Bingo! =)

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Thanks
The part with sending a message I knew it.

I assume that I have to put all my thread code in a big try catch, and when I catch something to send it to the main app.
Is this correct?

Regards
Dan Cimpoiesu

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:e3**************@TK2MSFTNGP10.phx.gbl...
Dan,

What you would have to do is wrap your thread code in an exception
handler. Once you do that, you will have to send a message to the main
thread (a Windows message) with the exception information. You can do this
by using the GCHandle structure. With it you can allocate a handle to an
object (the exception) and then pass it through a call to SendMessage
(through the P/Invoke layer). Then, in your main form, you can process

the
message (assuming you send using a custom message type, usuall WM_USER +
some number) getting the object back through the static methods on the
GCHandle structure.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:uI****************@tk2msftngp13.phx.gbl...
How can I make to route the exceptions from a thread created by my
Application, different that the Applications thread to the application. I want that when a exception occures in that thread, the application

to be aware of it and to display that default dialog for exceptions.

Regards
Dan Cimpoiesu



Nov 15 '05 #4
Thanks
:-)

Dan

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:uT**************@TK2MSFTNGP09.phx.gbl...
Dan,

Bingo! =)

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Thanks
The part with sending a message I knew it.

I assume that I have to put all my thread code in a big try catch, and

when
I catch something to send it to the main app.
Is this correct?

Regards
Dan Cimpoiesu

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>

wrote
in message news:e3**************@TK2MSFTNGP10.phx.gbl...
Dan,

What you would have to do is wrap your thread code in an exception
handler. Once you do that, you will have to send a message to the main thread (a Windows message) with the exception information. You can do

this
by using the GCHandle structure. With it you can allocate a handle to an object (the exception) and then pass it through a call to SendMessage
(through the P/Invoke layer). Then, in your main form, you can process
the
message (assuming you send using a custom message type, usuall WM_USER
+ some number) getting the object back through the static methods on the
GCHandle structure.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:uI****************@tk2msftngp13.phx.gbl...
> How can I make to route the exceptions from a thread created by my
> Application, different that the Applications thread to the

application. > I want that when a exception occures in that thread, the application

to
be
> aware of it and to display that default dialog for exceptions.
>
> Regards
> Dan Cimpoiesu
>
>



Nov 15 '05 #5
If you're developing a Windows app check out Application.OnThreadException

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:uI****************@tk2msftngp13.phx.gbl...
How can I make to route the exceptions from a thread created by my
Application, different that the Applications thread to the application.
I want that when a exception occures in that thread, the application to be
aware of it and to display that default dialog for exceptions.

Regards
Dan Cimpoiesu

Nov 15 '05 #6

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

Similar topics

11
by: Bob Rock | last post by:
Hello, coming from win32 API I recall an ExitThread() call to gently terminate a thread from inside the same thread .... but now all I can see is an Abort call which seems to me a wrapper on the...
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
7
by: David Elliott | last post by:
I have created an application that will dynamically load other DLLs (plugins). The new plugin is a winform with an embedded IE Browser. I am wanting to have the form to run in its own thread....
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...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
2
by: Robinson | last post by:
Hi, I have 2 menu items on the Debug menu of my application: Throw Exception On Form and Throw Exception In Worker Thread The former just executes: throw new Exception ( "I'm testing...
4
by: jayesah | last post by:
Hi All, I am writting a Thread class with using pthread library. I have some problem in saving thread function type and argument type. How to make Thread class generic ? /* This is my global...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
0
by: Buckaroo Banzai | last post by:
Hello, newbie here... I'm writing this program but when I click the start button which should initiate either the Hare or the Tortoise, it does not, this is the first time I use threads, so the...
18
by: J.K. Baltzersen | last post by:
To whomever it may concern: I am using MS Visual C++ 6.0. I have a process A which instantiates an object C. At a later point the process A creates the thread B. The thread B has access...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.