public void Test_Mutex() { SingleAppInstance sai = new SingleAppInstance(); bool flag1 = false, flag2 = false; Thread thread1 = new Thread(Func1); Thread thread2 = new Thread(Func2); thread1.Start(); thread2.Start(); void Func1() { flag1 = sai.StartMutex(); sai.CheckoutMutex(flag1); } void Func2() { flag2 = sai.StartMutex(); sai.CheckoutMutex(flag2); sai.FreeMutex(); } var expected = true; var result = !(flag1 && flag2); Assert.AreEqual(expected, result); }
private static void Main() { try { Log.Initialize(); SingleAppInstance.Initialize(); Translator.Initialize(); Config.UpgradeIfNotUpgraded(); if (Config.LoadOrSetByUser()) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += ThreadException; void ThreadException(object s, ThreadExceptionEventArgs t) { AskUserSendError(t.Exception); } Scaling.Initialize(); FolderOptions.Initialize(); using (new App()) { Log.WriteApplicationRuns(); Application.Run(); } } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) #pragma warning restore CA1031 // => Represents ThreadException during attached to process { AskUserSendError(ex); } finally { Log.Close(); } void AskUserSendError(Exception ex) { Log.Error("Application Crashed", ex); #warning [Feature] When Error ask user to send us #47, todo own dialog, lines here too long if (MessageBox.Show("A problem has been encountered and the application needs to restart. " + "Reporting this error will help us make our product better. Press yes to open your standard email app.", "SystemTrayMenu BugSplat", MessageBoxButtons.YesNo) == DialogResult.Yes) { Log.ProcessStart("mailto:" + "*****@*****.**" + "?subject=SystemTrayMenu Bug reported " + Assembly.GetEntryAssembly().GetName().Version + "&body=" + ex.ToString()); } AppRestart.ByThreadException(); } }
private static void Main() { try { Log.Initialize(); SingleAppInstance.Initialize(); Translator.Initialize(); Config.Initialize(); if (Config.LoadOrSetByUser()) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += ThreadException;