VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows

前端 未结 5 2155
忘了有多久
忘了有多久 2020-11-21 05:43

When I create a new project, I get a strange behavior for unhandled exceptions. This is how I can reproduce the problem:

1) create a new Windows Forms Application (C

5条回答
  •  别跟我提以往
    2020-11-21 06:00

    I'm using WPF and ran into this same problem. I had tried Hans 1-3 suggestions already, but didn't like them because studio wouldn't stop at where the error was (so I couldn't view my variables and see what was the problem).

    So I tried Hans' 4th suggestion. I was suprised at how much of my code could be moved to the MainWindow constructor without any issue. Not sure why I got in the habit of putting so much logic in the Load event, but apparently much of it can be done in the ctor.

    However, this had the same problem as 1-3. Errors that occur during the ctor for WPF get wrapped into a generic Xaml exception. (an inner exception has the real error, but again I wanted studio to just break at the actual trouble spot).

    What ended up working for me was to create a thread, sleep 50ms, dispatch back to main thread and do what I need...

        void Window_Loaded(object sender, RoutedEventArgs e)
        {
            new Thread(() =>
            {
                Thread.Sleep(50);
                CrossThread(() => { OnWindowLoaded(); });
            }).Start();
        }
        void CrossThread(Action a)
        {
            this.Dispatcher.BeginInvoke(a);
        }
        void OnWindowLoaded()
        {
            ...do my thing...
    

    This way studio would break right where an uncaught exception occurs.

提交回复
热议问题