public async Task CloseAsync(string message, WebSocketCloseStatus status = WebSocketCloseStatus.NormalClosure) { if (Socket == null) { return; } Task receiveTask = ReceiveLoop.StopAsync(); try { using var closeToken = new CancellationTokenSource(TimeSpan.FromSeconds(3)); await Socket?.CloseAsync(status, message, closeToken.Token); } catch (Exception e) { Console.WriteLine(String.Format("Exception while closing : {0}", e.ToString())); } finally { CancellationSource?.Cancel(); Socket?.Dispose(); Socket = null; CancellationSource?.Dispose(); CancellationSource = null; } }
private void SetUpCancellationSource(RasDialContext context) { CancellationSource?.Dispose(); CancellationSource = CancellationTokenSource.CreateLinkedTokenSource(context.CancellationToken); // Ensures that the connection can be cancelled even if the callback is stuck. CancellationSource.Token.Register(() => OnCancellationRequestedCallback(context)); }
protected override void Dispose(bool disposing) { if (disposing) { CancelAttemptIfBusy(); CancellationSource?.Dispose(); callbackHandler.Dispose(); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { if (IsBusy) { CancellationSource.Cancel(); } CancellationSource?.Dispose(); callbackHandler.Dispose(); } base.Dispose(disposing); }
private void SetUpCancellationSource(RasDialContext context) { CancellationSource?.Dispose(); CancellationSource = cancellationSourceFactory.Create(context.CancellationToken); }
public void Dispose() { CancellationSource.Dispose(); }
public void Dispose() { CancellationSource.Cancel(); CancellationSource.Dispose(); HttpUtils.Dispose(); }
public void Dispose() { _httpListener = null; CancellationSource.Dispose(); }