CLR 如何引发 ThreadAbortException?
如果使用 Thread.Abort 从另一个托管线程中止一个托管线程,那么 CLR 实际上如何在另一个线程上引发异常?看起来是个巧妙的技巧!
If you abort one managed thread from another, using Thread.Abort, how does the CLR actually throw the exception on the other thread? Seems like a neat trick!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了一些关于该主题的有趣链接。 ThreadAbortException是一种特殊情况,它由CLR专门处理。
http://mnikoo.net/2007/02/ 07/the-magic-of-the-clr-threadabortexception/
http://blogs.msdn.com/b/clrteam/archive/2009/04/28/threadabortexception.aspx
I've found a few interesting links on the subject. ThreadAbortException is a special case, and it is handled specially by the CLR.
http://mnikoo.net/2007/02/07/the-magic-of-the-clr-threadabortexception/
http://blogs.msdn.com/b/clrteam/archive/2009/04/28/threadabortexception.aspx
我不久前写了一篇关于此的博客文章。第一部分是关于何时可以中止线程,第二部分是关于它的实际工作原理。
我从未见过任何关于它实际工作原理的正确(在本例中为完整)文档,因此我写了有关它的文章。
要点是,CLR 将使用 SetThreadContext(一个 win32 api)来劫持您当前的 IP,并将您移至一个特殊的存根中,以便在您的线程未处于可中止等待状态时设置线程中止。
查看这里的帖子
I wrote a blog post on this awhile back. The first part is about when a thread can be aborted, the second is about how it actually works.
I hadn't ever seen any correct (in this case, complete) documentation about how it actually works, so I wrote about about it.
The jist is that the CLR will use SetThreadContext (a win32 api) to hijack your current IP and move you into a special stub to set up the thread abort if you're thread isn't in an abortable wait.
Check out the post here