예제 #1
0
        public async Task <string> Test()
        {
            var lockName  = "name";
            var lockToken = Guid.NewGuid().ToString("N");

            try
            {
                if (distributedLock.Enter(lockName, lockToken, TimeSpan.FromSeconds(30)))
                {
                    // do something
                    return("ok");
                }
                else
                {
                    return("error");
                }
            }
            finally
            {
                distributedLock.Exit(lockName, lockToken);
            }
        }
        public async Task <string> Test()
        {
            var lockName  = "name";
            var lockToken = Guid.NewGuid().ToString("N");

            try
            {
                if (distributedLock.Enter(lockName, lockToken, TimeSpan.FromSeconds(60), retryAttemptMillseconds: 1000, retryTimes: 10))
                {
                    await System.Threading.Tasks.Task.Delay(5000);

                    // do something
                    return("ok");
                }
                else
                {
                    return("error");
                }
            }
            finally
            {
                distributedLock.Exit(lockName, lockToken);
            }
        }