public ZKLock(ZKConfig config) { this.config = config; var tcs = new TaskCompletionSource <bool>(); lock (lockObj) { if (zooKeeper == null) { zooKeeper = new ZK.ZooKeeper( this.config.ConnectionString, this.config.SessionTimeout, new WaitWatcher(string.Empty, tcs, e => e.getState() == KeeperState.SyncConnected)); } } zooKeeper.Connect().Wait(); if (zooKeeper.getState() != ZK.ZooKeeper.States.CONNECTED && zooKeeper.getState() != ZK.ZooKeeper.States.CONNECTEDREADONLY) { throw new Exception("ZooKeeper Connected Failed"); } CreatNodeIfNotExist(config.LockPath).Wait(); Console.WriteLine($"{this.config.Name} Constructed"); }