我怎样才能在用户未处理的 例外情况下中断,以便像广告https://archive.is/090KL一样可靠地工作?
这是一个工作的例子,另一个失败了:
$>npm --version
$>1.3.10
$>sudo npm install -g --upgrade npm
$>npm --version
$>2.12.0
此程序中没有用户异常处理程序。此示例是Platform target x86并在Windows 7下运行。
答案 0 :(得分:1)
如果我修改Main()
静态线程,则在Windows 7上使用Visual Studio 2012和您的代码示例会导致抛出异常。
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Added this line and corresponding method
Application.ThreadException += Application_ThreadException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
}