[英]How can I get notification that my program has crashed
请参阅如何在.NET中指定控制台应用程序的退出代码? , MSDN: 控制台应用程序中的 Main()返回值(C#编程指南)和.NET全局异常处理程序 。
之所以显示该对话框,是因为您没有捕获异常。 您需要结合此处显示的所有内容,因此:
class Program {
static void Main(string[] args) {
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
// Your code here
throw new Exception("Kaboom");
}
static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e) {
Console.WriteLine(e.ExceptionObject.ToString());
Environment.Exit(1);
}
}
和:
@echo off
TestExceptionApp
@if "%ERRORLEVEL%" == "0" goto good
:fail
echo Execution Failed
echo return value = %ERRORLEVEL%
goto end
:good
echo Execution succeeded
echo Return value = %ERRORLEVEL%
goto end
:end
您必须编写一个单独的程序,以创建捕获错误的新进程。 捕获后,可以在错误处理通知之前在catch语句中向自己发送通知。
它可能需要作为从本地用户系统调用的单独程序运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.