Ensure State is Connected before raising DiscordClient.Connected

This commit is contained in:
RogueException
2016-01-13 04:24:31 -04:00
parent c1f24d164b
commit 2f8754091e

View File

@@ -99,10 +99,10 @@ namespace Discord.Net.WebSockets
try try
{ {
State = ConnectionState.Connected; State = ConnectionState.Connected;
_connectedEvent.Set();
Logger.Info($"Connected"); Logger.Info($"Connected");
OnConnected(); OnConnected();
_connectedEvent.Set();
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -173,8 +173,11 @@ namespace Discord.Net.WebSockets
try try
{ {
if (!_connectedEvent.Wait(_client.Config.ConnectionTimeout, cancelToken)) if (!_connectedEvent.Wait(_client.Config.ConnectionTimeout, cancelToken))
{
if (State != ConnectionState.Connected)
throw new TimeoutException(); throw new TimeoutException();
} }
}
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
_taskManager.ThrowException(); //Throws data socket's internal error if any occured _taskManager.ThrowException(); //Throws data socket's internal error if any occured