c# - ThreadAbortException -


Assume that we have some code that is running in a different thread like this:

 < Code> private static zero threadfunk () {ulong counter = 0; While {true} {try {Console.WriteLine ("{0}", counter ++); } Hold (ThreadAbertexposition) {Console.WriteLine ("abort!"); }}}  

When called thread.arbert () , is it possible that an exception is thrown out of the catch block?

Actually yes, there is one special even if you handle it, then it's CLR By automatically retry / hold / will be thrown at the end of the end. (As mentioned in the comments, it can be suppressed, but the code from that point smells like a fish.)

Not to mention that your efforts / grip / end There is no clear executable code outside, for every short time, every frequency of loop winds outside the scope can be out of your effort block.

Unless you're actually doing anything in the catch block, I just try one / end and do not worry about ThreadAbortException . There are better ways to leave the thread without any threads. Thank you which not only gets worse in your code at the pointless point of view, it is also not guaranteed to work because if your thread is currently unmanaged, the thread will not end until the control code is returned to the control.

Any kind of synchronization primitive, such as when using an exit to work your flag as a flag is better, you can also use the boolean field for this purpose What the background worker does.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -