1. The first version of the English-speaking SO. I briefly copy:
Add a class to call 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 start of the application:
[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 invalid context of the Form_Load call:
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"; }