public void TestDistributedDelayLock()
        {
            _zkClient.CreateRecursive(lockPath, null, CreateMode.Persistent);
            int           index   = 0;
            List <string> msgList = new List <string>();

            for (int i = 0; i < 5; i++)
            {
                Task.Factory.StartNew(() =>
                {
                    ZKClient zkClient1 = ZKClientBuilder.NewZKClient()
                                         .Servers(string.Format("{0}:{1}", TestUtil.ip, TestUtil.port))
                                         .SessionTimeout(10000)
                                         .Build();
                    ZKDistributedDelayLock _lock = ZKDistributedDelayLock.NewInstance(zkClient1, lockPath);
                    autoReset.WaitOne();

                    _lock.Lock();
                    Console.WriteLine(Thread.CurrentThread.Name + ":lock....");
                    msgList.Add(Thread.CurrentThread.Name + ":unlock");
                    try
                    {
                        Thread.Sleep(1000);
                    }
                    catch (ThreadInterruptedException e)
                    {
                    }
                    Console.WriteLine(Thread.CurrentThread.Name + ":unlock....");
                    _lock.UnLock();
                });
                Interlocked.Increment(ref index);
            }

            autoReset.Set();

            int size = TestUtil.WaitUntil(5, () => { return(msgList.Count); }, new TimeSpan(0, 0, 200));

            Assert.True(size == 5);
        }
        public void Requeue()
        {
            if (state != (int)State.STARTED)
            {
                throw new ZKException("close() has already been called");
            }

            isInterrupted = false;
            cancellationTokenSource.Cancel();
            SetFactory();

            //添加到参与者节点中
            AddParticipantNode();

            factory.StartNew(() =>
            {
                if (!factory.CancellationToken.IsCancellationRequested)
                {
                    _lock.Lock(0, delayTimeMillis);
                    listener.TakeLeadership(client, this);
                }
            });
        }