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

前端 未结 5 2140
忘了有多久
忘了有多久 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:06

    A simple work-around could be if you can move your init code to another event like as Form_Shown which called later than Form_Load, and use a flag to run startup code at first form shown:

    bool firstLoad = true; //flag to detect first form_shown
    
    private void Form1_Load(object sender, EventArgs e)
    {
        //firstLoad = true;
        //dowork(); //not execute initialization code here (postpone it to form_shown)
    }
    
    private void Form1_Shown(object sender, EventArgs e)
    {
        if (firstLoad) //simulate Form-Load
        {
            firstLoad = false;
    
            dowork();
        }
    }
    
    void dowork()
    {
        var f = File.OpenRead(@"D:\NoSuchFile756.123"); //this cause an exception!
    
    }
    

提交回复
热议问题