我怎样才能得到'在用户未处理的异常时中断'按照宣传的方式工作?

时间:2015-10-19 11:59:12

标签: visual-studio-2008

我怎样才能在用户未处理的 例外情况下中断,以便像广告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下运行。

1 个答案:

答案 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)
{
}