Debugger gets stuck in WPF OnStartup method

I am experiencing a problem in my project where if I get an exception in OnStartup code in App.xaml.cs debugger will breakpoint first and when I click continue it will run and breakpoint at the same location rather than exiting app.

However if I add DispatcherUnhandledException event handler in App.xaml.cs and empty event handler it will work as expected.

<Application x:Class="WpfApplication8.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             DispatcherUnhandledException="App_DispatcherUnhandledException"
             StartupUri="MainWindow.xaml">
    <Application.Resources />
</Application>

App.Xaml.cs

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        var b = 4 - 4;
        var a = 100/b;
    }

    void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args)
    {

    } 
}

To reproduce issue remove event handler from code behind.

Solution details: WPF, .Net 4 (with all current updates), Visual Studio 20013 update 3.

Could anyone explain why do I get this behaviour?

链接地址: http://www.djcxy.com/p/51234.html

上一篇: 在Python中调用exit()时,C ++析构函数中的互斥锁会导致异常

下一篇: 调试器卡在WPF OnStartup方法中