Browse Source

Dont crash if the websocket's cancelTokenSource.Cancel throws an exception

pull/97/head
RogueException 9 years ago
parent
commit
ff806d5468
1 changed files with 4 additions and 8 deletions
  1. +4
    -8
      src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs

+ 4
- 8
src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs View File

@@ -72,17 +72,13 @@ namespace Discord.Net.WebSockets
public async Task DisconnectAsync()
{
//Assume locked
_cancelTokenSource.Cancel();
try { _cancelTokenSource.Cancel(false); } catch { }
if (_client != null && _client.State == WebSocketState.Open)
{
try
{
var task = _client?.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
if (task != null)
await task.ConfigureAwait(false);
}
catch { }
var task = _client?.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
if (task != null)
await task.ConfigureAwait(false);
}
await (_task ?? Task.CompletedTask).ConfigureAwait(false);


Loading…
Cancel
Save