Exemplo n.º 1
0
        private void TouchMutexOnTimerFire(object state)
        {
            var mutex = _mutex;

            if (mutex != null)
            {
                _log.Debug("Touching mutex");
                ControlMutex.Touch(AdminConnectionString, Timeouts.AdminDatabase, mutex.Status.MutexValue);
            }
        }
Exemplo n.º 2
0
        private void InitMutex()
        {
            _mutex = ControlMutex.Grab(AdminConnectionString, Timeouts.AdminDatabase);
            if (!_mutex.Success)
            {
                _log.ErrorFormat(
                    "Mutex failure: {0}",
                    _mutex.Status.ToString());

                throw new ApplicationException("Could not get exclusive access to the staging database");
            }

            _mutexTimer = new Timer(
                TouchMutexOnTimerFire,
                null,
                MutexTimerIntervalSecs * 1000,
                MutexTimerIntervalSecs * 1000);
        }
Exemplo n.º 3
0
        private void CleanupMutex()
        {
            if (_mutexTimer != null)
            {
                _mutexTimer.Dispose();
                _mutexTimer = null;
            }

            if (_mutex != null)
            {
                Guid mutexValue = _mutex.Status.MutexValue;
                _mutex = null;

                if (mutexValue != Guid.Empty && _adminDatabaseAccessible)
                {
                    _log.DebugFormat("Releasing mutex: {0}", mutexValue);
                    ControlMutex.Release(AdminConnectionString, Timeouts.AdminDatabase, mutexValue);
                }
            }
        }