Esempio n. 1
0
        public async Task <AsyncOut <ILockFile> > TryAcquireLockAsync(string path)
        {
            try
            {
                if (await IsLockedInternalAsync(path))
                {
                    return(AsyncOut <ILockFile> .Empty);
                }

                var lockFile = new AsyncLockFile(_root, path, DateTime.UtcNow.ToString("u"), _asyncLock);
                return(new AsyncOut <ILockFile>(true, lockFile));
            }
            catch
            {
                // An error occured while reading/creating the lock file
                return(AsyncOut <ILockFile> .Empty);
            }
        }
Esempio n. 2
0
        public bool TryAcquireLock(string path, out ILockFile lockFile)
        {
            lockFile = null;

            try
            {
                if (IsLockedInternal(path))
                {
                    return(false);
                }

                lockFile = new AsyncLockFile(_root, path, DateTime.UtcNow.ToString("u"), _asyncLock);
                return(true);
            }
            catch
            {
                // An error occured while reading/creating the lock file
                return(false);
            }
        }