Strange behavior of exemptions in Form_Load



  • If there's a case in the processor Load There is an exception, but it is not displayed in the VS launch - the method is simply interrupted and the shape is displayed. It's happening both at the launch and at the dorm.

    In previous versions of the VS, this problem has been solved by the creation of a new configuration of a bill under x64. Although Empty had to be placed as a base, which was in itself uncomfortable, i.e., the levels of warning had to be re-established.

    But there's nothing good at VS2015. What do we do?

    https://cloud.mail.ru/public/2gj3ewrXbp5S/%D0%9F%D1%80%D0%BE%D0%B1%D0%BB%D0%B5%D0%BC%D1%8B%20%D1%81%20Form_Load.wmv (27MB).

    PS: Found some of these questions on enSO, but there are either creepy crutches or a description of what this is about the 32-bit of the annex.



  • 1. https://stackoverflow.com/a/11997142/119527 from English-speaking SO. I'm just digging.

    Add a class to challenge the required functions:

    public static class Kernel32
    {
        public const uint PROCESS_CALLBACK_FILTER_ENABLED = 0x1;
    
    [DllImport("Kernel32.dll")]
    public static extern bool SetProcessUserModeExceptionPolicy(UInt32 dwFlags);
    
    [DllImport("Kernel32.dll")]
    public static extern bool GetProcessUserModeExceptionPolicy(out UInt32 lpFlags);
    
    
    public static void DisableUMCallbackFilter() {
        uint flags;
        GetProcessUserModeExceptionPolicy(out flags);
    
        flags &= ~PROCESS_CALLBACK_FILTER_ENABLED;
        SetProcessUserModeExceptionPolicy(flags);
    }
    

    }

    Call it all at the beginning of the app:

    [STAThread]
    static void Main()
    {
    if (System.Diagnostics.Debugger.IsAttached)
    {
    Kernel32.DisableUMCallbackFilter();
    }

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
    

    }

    2. The second option is to break the inappropriate context of the Form_Load challenge:

        private void Form1_Load(object sender, EventArgs e)
    {
    if (System.Diagnostics.Debugger.IsAttached)
    {
    //Форме рано представать перед пользователем.
    this.WindowState = FormWindowState.Minimized;
    this.ShowInTaskbar = false;

            Task.Run(
                delegate
                {
                    //Это нужно, чтобы успеть посмотреть, как процесс
                    //загрузки будет выглядеть для пользователя.
                    //Thread.Sleep(3000);
    
                    this.Invoke(
                        new Action(delegate
                        {
                            FormLoadLogic();
    
                            //Теперь можно форму показать.
                            this.WindowState = FormWindowState.Normal;
                            this.ShowInTaskbar = true;
                        }));
                });
        }
        else
        {
            FormLoadLogic();
        }
    }
    
    FormLoadLogic()
    {
        this.Text = "step 1";
        throw new Exception("test");
        this.Text = "step 2";
    }
    




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2