有没有办法在VS中关闭/停止调试c#应用程序时运行短回调? [英] Is there a way to run a short callback when closing/stop debugging a c# application in VS?

查看:1362
本文介绍了有没有办法在VS中关闭/停止调试c#应用程序时运行短回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有几种方法可以禁用它在我的(wpf)应用程序(其中我连续ping),但有时我忘了这样做和BSOD。



我想通过改变一个全局AllowRealPinging变量和休眠

解决方案

这是Windows 7中的一个已知错误,您将得到一个BSOD与错误检查代码0x76,PROCESS_HAS_LOCKED_PAGES在tcpip.sys当您终止进程。最相关的反馈文章在这里。此问题也包含在此SO问题中。没有很好的答案,唯一已知的解决方法是回退到4.0之前的.NET版本,它使用另一个不触发驱动程序错误的winapi函数。



在调试时避免ping操作无疑是避免此问题的最佳方法。你想要的方法是不工作的,当你的程序遇到断点时,程序会完全冻结,当你停止调试时你的程序会完全冻结。



最简单的方法是只是不启动ping在具有附加的调试器的特定情况下首先。使用System.Diagnostic.Debugger.IsAttached属性在您的代码中检测这一点。


I'm running into the bug where it BSODon ending debugging in the middle of a ping.

I have a few ways to disable it in my (wpf) application (where I ping continuously), but sometimes I forget to do so and BSOD.

I'd like to get around that say by changing a global AllowRealPinging variable and sleeping for 2 seconds in a callback before exiting the debugger so I don't BSOD.

解决方案

This is a known bug in Windows 7, you'll get a BSOD with bug-check code 0x76, PROCESS_HAS_LOCKED_PAGES in tcpip.sys when you terminate the process. The most relevant feedback article is here. Also covered in this SO question. No great answers there, the only known workaround is to fallback to a .NET version earlier than 4.0, it uses another winapi function that doesn't trigger the driver bug.

Avoiding pinging while you debug is certainly the best way to avoid this problem. Your desired approach is not going to work, your program is entirely frozen when it hits a breakpoint, kaboom when you stop debugging.

The simplest way is to just not starting pinging in the first place in the specific case of having a debugger attached. Use the System.Diagnostic.Debugger.IsAttached property to detect this in your code.

这篇关于有没有办法在VS中关闭/停止调试c#应用程序时运行短回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆