简体   繁体   中英

Aborting the thread from inside the same thread

I created a thread A and decided to abort it from inside the thread A. Is that possible? If so how can I do that?

Thanks for the help!

Sure, you can do:

Thread.CurrentThread.Abort();

Arguably aborting the current thread is the only kind of abort that's safe, as it's the only thread you really know about in terms of what it's doing. This is what HttpResponse.End does, for example.

It's not something I would typically recommend - basically it's done because unless you explicitly call Thread.ResetAbort , the ThreadAbortException will propagate up the call stack regardless of catch blocks - it's a sort of "uber-exception" in that sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM