protected override void OnExit(ExitEventArgs e) { //Thread.Sleep(1000); GC.Collect(); GC.WaitForPendingFinalizers(); app?.Shutdown(); base.OnExit(e); }
protected override void OnExit(ExitEventArgs e) { using (var ev = new ManualResetEvent(false)) { app.SignalForShutdown(() => ev.Set()); ev.WaitOne(); } messagePump?.Dispose(); app?.Shutdown(); base.OnExit(e); }
static void Main(string[] args) { //Application.SetHighDpiMode(HighDpiMode.SystemAware); //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); string cefPath = Path.Combine(Path.GetDirectoryName(GetProjectPath()), "cef"); bool externalMessagePump = args.Contains("--external-message-pump"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; var settings = new CefSettings(); settings.MultiThreadedMessageLoop = !externalMessagePump; settings.ExternalMessagePump = externalMessagePump; settings.NoSandbox = true; settings.WindowlessRenderingEnabled = true; settings.LocalesDirPath = Path.Combine(cefPath, "Resources", "locales"); settings.ResourcesDirPath = Path.Combine(cefPath, "Resources"); settings.LogSeverity = CefLogSeverity.Warning; settings.IgnoreCertificateErrors = true; settings.UncaughtExceptionStackSize = 8; var app = new CefAppImpl(); app.ScheduleMessagePumpWorkCallback = OnScheduleMessagePumpWork; try { app.BeforeInitialize += App_BeforeInitialize; app.Initialize(Path.Combine(cefPath, "Release"), settings); if (externalMessagePump) { messagePump = new System.Threading.Timer(_ => Application.RunOnUIThread(CefApi.DoMessageLoopWork), null, messagePumpDelay, messagePumpDelay); } mainForm = new MainForm(); //mainForm.UseSystemDecorations = true; Application.Run(mainForm); } finally { messagePump?.Dispose(); app.Shutdown(); app.Dispose(); } }