/// <summary> /// Runs the specified delegate checking if this is the only instance of the application. /// </summary> /// <param name="Main"></param> /// <param name="Param"></param> /// <returns>Exit code.</returns> public static int RunSingleInstance(MainProc Main, object Param) { if (Environment.GetEnvironmentVariable("uebp_UATMutexNoWait") == "1") { return(Main(Param)); } var Result = 1; var bCreatedMutex = false; var LocationHash = InternalUtils.ExecutingAssemblyLocation.GetHashCode(); var MutexName = "Global/" + Path.GetFileNameWithoutExtension(ExecutingAssemblyLocation) + "_" + LocationHash.ToString() + "_Mutex"; using (Mutex SingleInstanceMutex = new Mutex(true, MutexName, out bCreatedMutex)) { if (!bCreatedMutex) { Log.WriteLine(TraceEventType.Warning, "Another instance of {0} is already running. Waiting until it exists.", ExecutingAssemblyLocation); // If this instance didn't create the mutex, wait for the existing mutex to be released by the mutex's creator. SingleInstanceMutex.WaitOne(); } else { Log.WriteLine(TraceEventType.Verbose, "No other instance of {0} is running.", ExecutingAssemblyLocation); } Result = Main(Param); SingleInstanceMutex.ReleaseMutex(); } return(Result); }
/// <summary> /// Runs the specified delegate checking if this is the only instance of the application. /// </summary> /// <param name="Main"></param> /// <param name="Param"></param> /// <returns>Exit code.</returns> public static int RunSingleInstance(MainProc Main, object Param) { if (Environment.GetEnvironmentVariable("uebp_UATMutexNoWait") == "1") { return(Main(Param)); } var Result = 1; var bCreatedMutex = false; var LocationHash = InternalUtils.ExecutingAssemblyLocation.GetHashCode(); var MutexName = "Global/" + Path.GetFileNameWithoutExtension(ExecutingAssemblyLocation) + "_" + LocationHash.ToString() + "_Mutex"; using (Mutex SingleInstanceMutex = new Mutex(true, MutexName, out bCreatedMutex)) { if (!bCreatedMutex) { throw new AutomationException("Another instance of {0} is already running.", ExecutingAssemblyLocation); } else { Log.WriteLine(TraceEventType.Verbose, "No other instance of {0} is running.", ExecutingAssemblyLocation); } Result = Main(Param); SingleInstanceMutex.ReleaseMutex(); } return(Result); }
/// <summary> /// Runs the specified delegate checking if this is the only instance of the application. /// </summary> /// <param name="Main"></param> /// <param name="Param"></param> /// <returns>Exit code.</returns> public static int RunSingleInstance(MainProc Main, object Param) { if (Environment.GetEnvironmentVariable("uebp_UATMutexNoWait") == "1") { return Main(Param); } var Result = 1; var bCreatedMutex = false; var LocationHash = InternalUtils.ExecutingAssemblyLocation.GetHashCode(); var MutexName = "Global/" + Path.GetFileNameWithoutExtension(ExecutingAssemblyLocation) + "_" + LocationHash.ToString() + "_Mutex"; using (Mutex SingleInstanceMutex = new Mutex(true, MutexName, out bCreatedMutex)) { if (!bCreatedMutex) { Log.WriteLine(TraceEventType.Warning, "Another instance of {0} is already running. Waiting until it exists.", ExecutingAssemblyLocation); // If this instance didn't create the mutex, wait for the existing mutex to be released by the mutex's creator. SingleInstanceMutex.WaitOne(); } else { Log.WriteLine(TraceEventType.Verbose, "No other instance of {0} is running.", ExecutingAssemblyLocation); } Result = Main(Param); SingleInstanceMutex.ReleaseMutex(); } return Result; }
public void RefreshStatusBarThread() { int counter = 0; Font df = StatusBarMemory.Font; RefreshStatusBarDel del = new RefreshStatusBarDel(RefreshStatusBarDelProc); //CountDownThreadDel del_d = new CountDownThreadDel(CountDownThreadDelProc); int val = 0; while (Common.IsRunning) { try { Thread.Sleep(100); if (counter > 5) { MainProc.Refresh(); long mem = MainProc.PagedMemorySize64 + MainProc.PagedSystemMemorySize64; StatusBarMemory.Text = (mem / 1024).ToString() + "k"; if (mem > Common.Conf.ValidMemoryUsage * 1000000) { if (MemoryLikInformed == false) { MemoryLikInformed = true; MemLInfo msg = new MemLInfo(); msg.ShowDialog(MForm); } if (StatusBarMemory.ForeColor != Color.Red) { StatusBarMemory.ForeColor = Color.Red; StatusBarMemory.Font = new Font(FontFamily.GenericSansSerif, 15, FontStyle.Bold); } } else { if (StatusBarMemory.ForeColor != Color.Black) { StatusBarMemory.ForeColor = Color.Black; StatusBarMemory.Font = df; } } counter = 0; } else { counter++; } if (CountDownTime > 0) { float dlt = (DateTime.Now.Ticks - CountDownFrom) / 10000000F; val = (int)(StatusBarProgress.Maximum - StatusBarProgress.Maximum * dlt / CountDownTime); if (val < 0) { val = 0; } } else { val = 0; } if (TimeScrollVal != val) { TimeScrollVal = val; NeedStatusBarRefresh = true; } if (NeedStatusBarRefresh) { NeedStatusBarRefresh = false; MForm.Invoke(del); } } catch { } } }