public IHttpActionResult Mutex() { ParameterizedThreadStart pt = (x) => { }; pt.Invoke(DateTime.Now); Mutex mutex = new Threading.Mutex(); return(Json(mutex)); }
private static void OnExit(object sender, EventArgs e) { try { if (!oMutex == null) { oMutex.ReleaseMutex(); ((IDisposable)oMutex).Dispose(); oMutex = null; } } catch { //Do Nothing } }
static SingleInstance() { _mcThisAppID = System.Reflection.Assembly.GetExecutingAssembly().FullName; oMutex = new Threading.Mutex(true, _mcThisAppID + "_APPLICATION_MUTEX", _MutexOwned); if (!_MutexOwned) { //modified DE //try to find window for 5 secs _MutexOwned = true; System.DateTime TmpStart = Now; do { if (FindWindow()) { //another window found _MutexOwned = false; break; // TODO: might not be correct. Was : Exit Do } Threading.Thread.Sleep(250); } while ((DateDiff(DateInterval.Second, DateAdd(DateInterval.Second, 5, TmpStart), Now) < 0)); } AppDomain.CurrentDomain.ProcessExit += OnExit; }