Exemple #1
0
            public void OnConnectionClosed(ITcpConnection connection, SocketError socketError)
            {
                var operateID = Guid.NewGuid().ToString();
                var lockkey   = connection.RemotingEndPoint.ToString();

                if (_lock.LockTake(lockkey, operateID, TimeSpan.FromSeconds(10)))
                {
                    _clientPool.ConnectedClientList.Remove(_client);
                    _clientPool.CurrentCount -= 1;
                    _lock.LockRelease(lockkey, operateID);
                }
                else
                {
                    OnConnectionClosed(connection, socketError);
                }
            }
 /// <summary>
 /// 获取一个锁(需要自己释放)
 /// </summary>
 /// <param name="lock">业务锁</param>
 /// <param name="key">锁定标识</param>
 /// <param name="expiration">锁定时间间隔</param>
 /// <returns>true:成功锁定; false:之前已被锁定</returns>
 public static bool LockTak(this ILock @lock, string key, TimeSpan expiration) => @lock.LockTake(key, "1", expiration);