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); }
public void Disconnect(IPEndPoint remote) { _network.Disconnect(remote); }