示例#1
0
        public bool AquireLock()
        {
            bool result = true;

            _lockService = IoC.Container.Resolve <ILockService>(); //new LockService(_connectionString);
            foreach (string lockID in _lockKeys)
            {
                bool firstPass = _lockService.AquireLock(lockID);

                if (!firstPass)
                {
                    System.Threading.Thread.Sleep(500 * (ThreadNumber + 1));
                    result = result && _lockService.AquireLock(lockID);
                    if (!result)
                    {
                        _lockService.ReleaseAllLocks();
                        break;
                    }
                }
                else
                {
                    result = result && firstPass;
                }
            }
            return(result);
        }
示例#2
0
 public void ReleaseLock()
 {
     if (_lockService != null)
     {
         foreach (string lockID in _lockKeys)
         {
             _lockService.ReleaseLock(lockID);
         }
         _lockService.ReleaseAllLocks();
     }
 }