运行 Visual Studio 中托管的调试应用程序与直接运行它时的 Thread.Abort()
我们有一个线程,当我们从外部调用 Thread.Abort() 时,会捕获 ThreadAbortException,因为我们需要进行一些清理工作。特别是需要一个互斥锁。在 Visual Studio 之外以调试模式运行应用程序时,此问题会崩溃,但在 Visual Studio 中托管时,一切运行正常。我听说托管与未托管时垃圾收集器的运行方式有所不同。这可能与线程有关吗?抛出的错误是缓冲区溢出。
谢谢 !
We have a thread in which, when we externally call Thread.Abort(), a ThreadAbortException is caught because we have some cleanup to do. In particular, a Mutex is requested. This crashes when running the application in debug mode outside of Visual Studio, but when hosted in Visual Studio, all runs fine. I heard the garbage collector runs differently when hosted vs. when not hosted. Could that have something to do with threads ? The error thrown is a buffer overrun.
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Henk 已经指出的那样,不要调用 Thread.Abort。曾经。
我的博客上有一些信息 关于垃圾收集器在不同情况下如何不同地工作。但是,我相信 GC 对于在调试器中或在调试器外运行调试构建是相同的。
如果您想回答其他问题,则需要发布更多信息。 “坠毁”不是一个描述性术语;应用程序是否突然退出,或弹出您编写的对话框,或弹出 Windows 错误报告?同样,我不熟悉“缓冲区溢出”异常;对于异常,请发布异常类型、消息和完整的堆栈跟踪。
As Henk already pointed out, don't call
Thread.Abort
. Ever.I have some information on my blog about how the garbage collector works differently in different situations. However, I believe that GC is the same for running a Debug build in or out of the debugger.
If you want other questions answered, you'll need to post more info. "Crashed" is not a descriptive term; does the application suddenly exit, or bring up a dialog you wrote, or bring up Windows Error Reporting? Similarly, I'm not familiar with a "buffer overrun" exception; for an exception, please post the exception type, message, and complete stack trace.