,The only exception you can seed into some working thread totally asynchronously to this thread is the
System.Threading.ThreadAbortException
, which is done only by runtime system as a result of thread abort:
https://msdn.microsoft.com/en-us/library/system.threading.threadabortexception%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.threading.thread.abort%28v=vs.110%29.aspx[
^].
This technique is related to exception
seeding.
This approach is quite adequate but is considered as dangerous my many; I, as a person who understands how it works under the hood, use it but would just warn that using it requires good understanding of what you are doing. Please see my past answers,
Close correcly the thread inside a dll[
^],
Problem with creating Process from dedicated thread[
^].
All other exceptions can only use
cooperative approach; they should be thrown in the same thread. To, understand why, some deeper understanding of exception mechanism is needed. Please see my past answers:
Does Exception in C# Constructor Cause Caller Assignment to Fail?[
^],
where was stored .net exceptions in operating system[
^].
The example of such cooperative approach is the mechanism of
System.Threading.CancellationToken
you already use:
https://msdn.microsoft.com/en-us/library/system.threading.cancellationtoken%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.threading.cancellationtokensource%28v=vs.110%29.aspx[
^].
You only request the cancellation from some other thread (main thread), but exception is thrown in the same very thread which should be cancelled. Please see the code samples in the articles referenced above.
—SA