Thread exception

  • Thread starter Thread starter Dan Cimpoiesu
  • Start date Start date
D

Dan Cimpoiesu

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
 
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.
 
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 said:
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]
- (e-mail address removed)

Dan Cimpoiesu said:
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
 
Dan,

Bingo! =)

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

Dan Cimpoiesu said:
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

in message news:[email protected]...
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]
- (e-mail address removed)

Dan Cimpoiesu said:
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
 
Thanks
:-)

Dan

Nicholas Paldino said:
Dan,

Bingo! =)

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

Dan Cimpoiesu said:
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

in message news:[email protected]...
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]
- (e-mail address removed)

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