/// <summary> /// Event tratment: unload splash screen /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void frmExplorer_Load(object sender, EventArgs e) { //close splash if (frmSplashScreen == null) { return; } frmSplashScreen.Invoke(new Action(frmSplashScreen.Close)); frmSplashScreen.Dispose(); frmSplashScreen = null; }
static void NormalLoadind(string[] args, int numinstance) { #region normal loading Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Retrieve previous settings if update // (settings are lost if new version (thanks to MS) #region restore previous settings if app update PrgAutoUpdater.Util.DoUpgrade(Properties.Settings.Default); #endregion // Select language #region culture // Get current culture string m_lang = Properties.Settings.Default.lang; if (m_lang == "Undefined") //default value of Karaboss { ///The ClearCachedData method does not refresh the information in the Thread.CurrentCulture property for existing threads ///So you will need to first call the function and then start a new thread. ///In this new thread you can use the CurrentCulture to obtain the fresh values of the culture. Thread.CurrentThread.CurrentCulture.ClearCachedData(); var thread = new Thread( s => ((State)s).Result = Thread.CurrentThread.CurrentCulture); thread.IsBackground = true; var state = new State(); thread.Start(state); thread.Join(); var culture = state.Result; if (culture.IetfLanguageTag == "fr-FR") { m_lang = "Français"; } else { m_lang = "English"; } Properties.Settings.Default.lang = m_lang; Properties.Settings.Default.Save(); } // Change the culture for the App domain // Allow to manage languages for usercontrols switch (m_lang) { case "English": RuntimeLocalizer.ChangeCulture("en-US"); break; case "Français": RuntimeLocalizer.ChangeCulture("fr-FR"); break; default: RuntimeLocalizer.ChangeCulture("en-US"); break; } #endregion // check if update is available #region check and download new version program bool bCheckUpdates = Properties.Settings.Default.CheckForUpdates; Configuration.UpdFrequency UpdateFrequency = new Configuration.UpdFrequency(Properties.Settings.Default.UpdFrequency); // If check for update && date is overcome if (bCheckUpdates == true && UpdateFrequency.searchForUpdate()) { // Save last check date UpdateFrequency.saveUpdDate(DateTime.Now); bool bHasError = false; Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; string fileName = System.Reflection.Assembly.GetEntryAssembly().Location; FileInfo f = new FileInfo(fileName); long size = f.Length; string RemoteUrl = Properties.Settings.Default.RemoteUrl; IAutoUpdater autoUpdater = new AutoUpdater(Application.ProductName, version, size, RemoteUrl); try { autoUpdater.Update(); // check if remote URL has changed string url = autoUpdater.getRemoteUrl(); if (url.ToLower() != RemoteUrl.ToLower()) { Properties.Settings.Default.RemoteUrl = url; Properties.Settings.Default.Save(); } } catch (WebException exp) { MessageBox.Show("Can not find the specified resource. " + exp.Message); bHasError = true; } catch (XmlException exp) { bHasError = true; MessageBox.Show("Download the upgrade file error. " + exp.Message); } catch (NotSupportedException exp) { bHasError = true; MessageBox.Show("Upgrade address configuration error. " + exp.Message); } catch (ArgumentException exp) { bHasError = true; MessageBox.Show("Download the upgrade file error. " + exp.Message); } catch (Exception exp) { bHasError = true; MessageBox.Show("An error occurred during the upgrade process. " + exp.Message); } finally { if (bHasError == true) { try { //autoUpdater.RollBack(); } catch (Exception) { //Log the message to your file or database } } } } // bCheckUpdates #endregion //show splash screen #region splash Thread splashThread = new Thread(new ThreadStart( delegate { frmSplashScreen = new frmSplashScreen(); Application.Run(frmSplashScreen); } )); splashThread.IsBackground = true; splashThread.SetApartmentState(ApartmentState.STA); splashThread.Start(); #endregion // Display main form frmExplorer frmExplorer = new frmExplorer(args, numinstance); frmExplorer.Load += new EventHandler(frmExplorer_Load); frmExplorer.Show(); frmExplorer.Activate(); frmExplorer.BringToFront(); Application.Run(frmExplorer); #endregion }