static private void ShowForm() { try { splashForm = new FormSplash(); Application.Run(splashForm); } catch { } finally { splashForm = null; } }
static public void CloseFormAndWait() { if (_waitForUserCloseSplash != null) { throw new Exception("Should be null"); } while (splashForm == null) { Task.Delay(3).Wait(); } while (!splashForm.IsHandleCreated) { Task.Delay(3).Wait(); } if (splashForm == null) { throw new Exception("Can't close when not open"); } if (splashForm == null && !splashForm.IsHandleCreated) { new Exception("Missing handler"); } if (NeedShowWarningAndWaitUser()) { _waitForUserCloseSplash = new AutoResetEvent(false); } CloseForm(); if (_waitForUserCloseSplash != null) { _waitForUserCloseSplash.WaitOne(); } _waitForUserCloseSplash = null; splashForm = null; }
static void Main() { /* * // Add the event handler for handling UI thread exceptions to the event. * Application.ThreadException += new ThreadExceptionEventHandler(Form1_UIThreadException); * // Set the unhandled exception mode to force all Windows Forms errors to go through our handler. * Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); * // Add the event handler for handling non-UI thread exceptions to the event. * AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); */ Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); FormSplash.ShowSplashScreen("PhotoTags Synchronizer - Loading...", 21, Properties.Settings.Default.CloseWarningWindowsAutomatically, true); FormSplash.UpdateStatus("Initialize DLL files..."); //1 if (Environment.Is64BitProcess) { File.Copy( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x64\\sqlite3.dll"), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sqlite3.dll"), true); } else { File.Copy( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x86\\sqlite3.dll"), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sqlite3.dll"), true); } //Monitor parent process exit and close subprocesses if parent process exits first //This will at some point in the future becomes the default FormSplash.UpdateStatus("Initialize ChromiumWebBrowser - settings 1/2..."); //2 CefSharpSettings.SubprocessExitIfParentProcessClosed = true; //Cef.EnableHighDPISupport(); //Will remove 1.25 scaling, but Krypron will not work. var settings = new CefSettings() { //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data CachePath = FileHandler.GetLocalApplicationDataPath("BrowserCache", false, null), UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0" }; FormSplash.UpdateStatus("Initialize ChromiumWebBrowser - settings 2/2..."); //3 settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enables WebRTC //settings.CefCommandLineArgs.Add("force-device-scale-factor", "1"); settings.CefCommandLineArgs.Add("disable-gpu", "1"); //https://stackoverflow.com/questions/52913442/cefsharp-winforms-dock-dockstyle-fill-no-effect-black-edge-how-to-make-the-c FormSplash.UpdateStatus("Initialize ChromiumWebBrowser - starting process..."); //4 //Perform dependency check to make sure all relevant resources are in our output directory. Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); FormSplash.UpdateStatus("Initialize ChromiumWebBrowser - process started..."); //5 mainForm = new MainForm(); //this takes ages Application.Run(mainForm); }