public App() { if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "Updater001.exe")) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.UseShellExecute = true; startInfo.WorkingDirectory = System.AppDomain.CurrentDomain.BaseDirectory; startInfo.FileName = "powershell.exe"; startInfo.Arguments = "-WindowStyle hidden start-sleep 5;Remove-Item -Path .\\Updater.exe; Move-Item -Path .\\Updater001.exe -Destination .\\Updater.exe;"; Process.Start(startInfo); } ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13; uniqueMutex = new Mutex(true, uniqueAppGuid, out bool gotMutex); GC.KeepAlive(App.uniqueMutex); if (SingleInstance.IsFirstInstance(uniqueAppGuid, true)) { SingleInstance.OnSecondInstanceStarted += SingleInstance_OnSecondInstanceStarted; } else { // second instance so notify first instance SingleInstance.NotifyFirstInstance(uniqueAppGuid); } if (!gotMutex) { App.Current.Shutdown(); // only one instance of the app opened at a time so shutdown return; } }
static void Main() { Trace(LoggingTag, "SwerveToolsTray starting..."); // SingleInstance singleInstance = new SingleInstance(TrayUniquifier); if (singleInstance.IsFirstInstance()) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new TrayApplicationContext()); } else { Trace(LoggingTag, "not first instance"); } // Trace(LoggingTag, "...exiting SwerveToolsTray"); }
public App() { uniqueMutex = new Mutex(true, uniqueAppGuid, out bool gotMutex); GC.KeepAlive(App.uniqueMutex); if (SingleInstance.IsFirstInstance(uniqueAppGuid, true)) { SingleInstance.OnSecondInstanceStarted += SingleInstance_OnSecondInstanceStarted; } else { // second instance so notify first instance SingleInstance.NotifyFirstInstance(uniqueAppGuid); } if (!gotMutex) { App.Current.Shutdown(); // only one instance of the app opened at a time so shutdown return; } }