Don't destroy disconnectReason so quickly

This commit is contained in:
Brandon Smith
2015-09-04 19:25:01 -03:00
parent 5b432769fb
commit 8f7492c246
3 changed files with 10 additions and 4 deletions

View File

@@ -42,7 +42,10 @@ namespace Discord
}
catch (OperationCanceledException)
{
_disconnectReason.Throw();
if (_disconnectReason == null)
throw new Exception("An unknown websocket error occurred.");
else
_disconnectReason.Throw();
}
try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler
catch (OperationCanceledException) { return; }

View File

@@ -109,7 +109,10 @@ namespace Discord
}
catch (OperationCanceledException)
{
_disconnectReason.Throw();
if (_disconnectReason == null)
throw new Exception("An unknown websocket error occurred.");
else
_disconnectReason.Throw();
}
SetConnected();

View File

@@ -45,6 +45,7 @@ namespace Discord
await DisconnectAsync();
_disconnectToken = new CancellationTokenSource();
_disconnectReason = null;
var cancelToken = _disconnectToken.Token;
_webSocket = new ClientWebSocket();
@@ -78,8 +79,7 @@ namespace Discord
_webSocket = null;
byte[] ignored;
while (_sendQueue.TryDequeue(out ignored)) { }
_disconnectReason = null;
_task = null;
if (_isConnected)
{