By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Throwing an exception on a thread....

P: n/a
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 exception handling here" )

but I want the second to make my worker thread throw an exception too. I
thought about using Thread.Abort to make it throw a thread abort exception,
but I would rather somehow raise the exception on the thread in a more
general way (i.e. a general exception, or an exception type of my choosing).
As the worker thread performs one of a hundred or so different operations, I
don't want to have to insert "throw now" logic into every single operation
and, moreover, this will make the exception throw at the same place each
time, not good for testing.

So, in short, is it possible to throw an exception from one thread to be
handled on another?


Nov 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
>So, in short, is it possible to throw an exception from one thread to be
>handled on another?
Not just like that. You have to use some kind of thread
synchronization machanism, such as a ManualResetEvent, to signal the
the thread to execute the code you want.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '06 #2

P: n/a
Not just like that. You have to use some kind of thread
synchronization machanism, such as a ManualResetEvent, to signal the
the thread to execute the code you want.
Okay, I thought that might be the case. Thanks anyway.
Nov 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.