static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext()); Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; Program5a p = new Program5a(); p.ExitRequested += p_ExitRequested; Task programStart = p.StartAsync(); HandleExceptions(programStart); Application.Run(); }