/// <summary> /// Method used to disconnect this client. /// </summary> public void Disconnect() { _sender.Disconnect(); _receiver.Disconnect(); _sender.Disconnected -= OnConnectionDisconnected; _receiver.Disconnected -= OnConnectionDisconnected; IsConnected = false; }
private void OnConnectionDisconnected(object sender, EventArgs e) { if (!_isDisconnecting) { _isDisconnecting = true; if (_closedSignal != null) { _closedSignal.SetResult("close"); _closedSignal = null; } if (sender == _sender) { _receiver.Disconnect(); } if (sender == _receiver) { _sender.Disconnect(); } Disconnected?.Invoke(this, DisconnectedEventArgs.Empty); _isDisconnecting = false; } }
private void OnConnectionDisconnected(object sender, EventArgs e) { bool doDisconnect = false; if (!_isDisconnecting) { lock (_syncLock) { if (!_isDisconnecting) { _isDisconnecting = true; doDisconnect = true; } } } if (doDisconnect) { try { if (_sender.IsConnected) { _sender.Disconnect(); } if (_receiver.IsConnected) { _receiver.Disconnect(); } Disconnected?.Invoke(this, DisconnectedEventArgs.Empty); if (_autoReconnect) { // Try to rerun the client connection Background.Run(ConnectAsync); } } finally { lock (_syncLock) { _isDisconnecting = false; } } } }
/// <summary> /// Disconnects the NamedPipeServer. /// </summary> public void Disconnect() { _sender.Disconnect(); _receiver.Disconnect(); }