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

This commit is contained in:
RogueException
2016-06-21 01:10:17 -03:00
parent b38455f427
commit ff806d5468

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);