I want to pass an exception from current thread (that thread isn’t main thread)to main thread.
Why? Because I check my hard lock in another thread (that thread use timer for checking), and when HardLock is not accessible or invalid, I create an exception which is defined by myself and then throw that exception.
So that exception doesn’t work well. ;(
I want to pass an exception from current thread (that thread isn’t main thread)to
Share
Your best bet is to replace the
Threadwith aTask(new in .NET 4.0). TheTaskclass handles proper marshaling of the exception to whatever thread checks the result of the task.If using .NET 4.0 is not possible, then CoreEx.dll from the Rx extensions includes an
Exception.PrepareForRethrowextension method that preserves the call stack for exceptions. You can use this in conjunction with MaLio’s suggestion ofSynchronizationContextto marshal an exception to another thread.