private async void NetworkClient_OnDisconnected(object sender, Network.Events.DisconnectedEventArgs e) { IsConnected = false; while (!await AttemptConnectAsync(true)) { await Task.Delay(1000); } }
private void NetworkClient_OnDisconnected(object sender, Network.Events.DisconnectedEventArgs e) { lock (_connectedClients) { _connectedClients.Remove(sender as NetworkClient); } OnClientDisconnected?.Invoke(this, new ClientDisconnectedEventArgs(sender as NetworkClient)); }
private async void NetworkClient_OnDisconnected(object sender, Network.Events.DisconnectedEventArgs e) { #pragma warning disable CS4014 Task.Run(() => OnNetworkClientDisconnected?.Invoke(this, new DisconnectedEventArgs())); #pragma warning restore CS4014 IsConnected = false; try { while (!await AttemptConnectAsync(true)) { await Task.Delay(1000).WithCancellation(_clientCancellationToken.Token); } } catch (OperationCanceledException ex) { // Catch, consume, adapt, overcome } }