使用Ping时蓝屏

我遇到了BSODon在ping中间结束debugging的问题。

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

我想通过改变一个全局的AllowRealPingingvariables,并在退出debugging器之前在callback中hibernate2秒来解决这个问题,所以我不BSOD。

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

在debugging时避免执行ping命令肯定是避免此问题的最佳方法。 你所期望的方法是不行的,当你的程序遇到断点时,程序完全冻结,当你停止debugging的时候,程序会被完全冻结。

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

这是一个好方法:

private void GetPing(){ Dictionary<string, string> tempDictionary = this.tempDictionary; //Some adresses you want to test StringBuilder proxy = new StringBuilder(); string roundTripTest = ""; string location; int count = 0; //Count is mainly there in case you don't get anything Process process = new Process{ StartInfo = new ProcessStartInfo{ FileName = "ping.exe", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, } }; for (int i = 0; i < tempDictionary.Count; i++){ proxy.Append(tempDictionary.Keys.ElementAt(i)); process.StartInfo.Arguments = proxy.ToString(); do{ try{ roundTripTest = RoundTripCheck(process); } catch (Exception ex){ count++; } if (roundTripTest == null){ count++; } if (count == 10 || roundTripTest.Trim().Equals("")){ roundTripTest = "Server Unavailable"; } } while (roundTripTest == null || roundTripTest.Equals(" ") || roundTripTest.Equals("")); } process.Dispose(); } 

RoundTripCheck方法,魔术发生的地方:

  private string RoundTripCheck(Process p){ StringBuilder result = new StringBuilder(); string returned = ""; p.Start(); while (!p.StandardOutput.EndOfStream){ result.Append(p.StandardOutput.ReadLine()); if (result.ToString().Contains("Average")){ returned = result.ToString().Substring(result.ToString().IndexOf("Average =")) .Replace("Average =", "").Trim().Replace("ms", "").ToString(); break; } result.Clear(); } return returned; } 

我有同样的问题,这解决了它!

我不知道该怎么做。 但是,如果你没有find办法做到这一点,这里是一个build议:

  • 使用虚拟机来debugging您的程序。 即使发生BSOD,你将不得不重新启动虚拟机,而不是真正的电脑。 在开发内核/驱动程序时确实有帮助。
Interesting Posts