觸發,所以我嘗試添加「AppDomain.CurrentDomain.UnhandledException
」處理程序,以我的應用程序和它的工作確定,如果我錯誤記錄到一個文本文件中。但是當我嘗試使用MessageBox時,它永遠不會彈出。它是.Net中的另一個bug嗎?有任何想法嗎?MessageBox的時候「未處理的異常」中的WinForms
這裏是我的代碼示例:
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
,這裏是我的處理方法:
static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = (Exception)e.ExceptionObject;
MessageBox.Show("Whoops! Please contact the developers with "
+ "the following information:\r\n\r\n" + ex.Message + ex.StackTrace,
"Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally
{
Application.Exit();
}
}
編輯:我已經嘗試了所有可能的選擇,但我還是不能看消息框。現在的問題是,當我從Visual C#運行它(調試模式)時,它完美地顯示了該框。但是當我直接從調試運行應用程序/文件夾釋放它不會顯示在MessageBox和應用程序繼續運行,就像沒有錯誤發生...
我沒有問題與您的代碼,一切工作正常....(我有tryed與.net 2.0和4.0編譯,兩個作品) – punker76 2012-02-08 12:03:11
@ punker76 - 嗯這很奇怪。你在64位機器上? – SolidSnake 2012-02-08 12:15:18
我編譯爲在64位機Win7和VS2010 – punker76 2012-02-08 12:27:21