| @@ -42,7 +42,10 @@ namespace Discord | |||||
| } | } | ||||
| catch (OperationCanceledException) | 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 | try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler | ||||
| catch (OperationCanceledException) { return; } | catch (OperationCanceledException) { return; } | ||||
| @@ -109,7 +109,10 @@ namespace Discord | |||||
| } | } | ||||
| catch (OperationCanceledException) | catch (OperationCanceledException) | ||||
| { | { | ||||
| _disconnectReason.Throw(); | |||||
| if (_disconnectReason == null) | |||||
| throw new Exception("An unknown websocket error occurred."); | |||||
| else | |||||
| _disconnectReason.Throw(); | |||||
| } | } | ||||
| SetConnected(); | SetConnected(); | ||||
| @@ -45,6 +45,7 @@ namespace Discord | |||||
| await DisconnectAsync(); | await DisconnectAsync(); | ||||
| _disconnectToken = new CancellationTokenSource(); | _disconnectToken = new CancellationTokenSource(); | ||||
| _disconnectReason = null; | |||||
| var cancelToken = _disconnectToken.Token; | var cancelToken = _disconnectToken.Token; | ||||
| _webSocket = new ClientWebSocket(); | _webSocket = new ClientWebSocket(); | ||||
| @@ -78,8 +79,7 @@ namespace Discord | |||||
| _webSocket = null; | _webSocket = null; | ||||
| byte[] ignored; | byte[] ignored; | ||||
| while (_sendQueue.TryDequeue(out ignored)) { } | while (_sendQueue.TryDequeue(out ignored)) { } | ||||
| _disconnectReason = null; | |||||
| _task = null; | _task = null; | ||||
| if (_isConnected) | if (_isConnected) | ||||
| { | { | ||||