示例#1
0
        public async Task StartAsync()
        {
            _cancellationToken = new CancellationTokenSource();

            var token = _cancellationToken.Token;
            await Task.Run(async() =>
            {
                while (!token.IsCancellationRequested)
                {
                    var time        = GetTime();
                    var connections = _remoteToLastActive.ToDictionary(k => k.Key, v => v.Value);

                    foreach (var item in connections)
                    {
                        if (item.Value + Interval * TimeSpan.TicksPerMillisecond > time)
                        {
                            continue;
                        }

                        if (!_remoteToLastActive.TryRemove(item.Key, out _))
                        {
                            continue;
                        }

                        _network.Disconnect(item.Key);
                    }

                    await Task.Delay(CHECK_INTERVAL);
                }
            },
                           token);
        }
示例#2
0
文件: CoreAPI.cs 项目: bugRanger/Chat
 public void Disconnect(IPEndPoint remote)
 {
     _network.Disconnect(remote);
 }