Browse Source

Don't crash if a reconnect attempt fails

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
6abd07e0bf
1 changed files with 16 additions and 4 deletions
  1. +16
    -4
      Discord.Net/DiscordClient.cs

+ 16
- 4
Discord.Net/DiscordClient.cs View File

@@ -13,7 +13,10 @@ namespace Discord
{
public partial class DiscordClient
{
private DiscordWebSocket _webSocket;
public const int ReconnectDelay = 1000; //Time in milliseconds to wait after an unexpected disconnect before retrying
public const int FailedReconnectDelay = 10000; //Time in milliseconds to wait after a failed reconnect attempt

private DiscordWebSocket _webSocket;
private HttpOptions _httpOptions;
private bool _isClosing, _isReady;

@@ -172,10 +175,19 @@ namespace Discord
{
//Reconnect if we didn't cause the disconnect
RaiseDisconnected();
if (!_isClosing)
while (!_isClosing)
{
await Task.Delay(1000);
await _webSocket.ConnectAsync(Endpoints.WebSocket_Hub, _httpOptions);
try
{
await Task.Delay(ReconnectDelay);
await _webSocket.ConnectAsync(Endpoints.WebSocket_Hub, _httpOptions);
break;
}
catch (Exception)
{
//Net is down? We can keep trying to reconnect until the user runs Disconnect()
await Task.Delay(FailedReconnectDelay);
}
}
};
_webSocket.GotEvent += (s, e) =>


Loading…
Cancel
Save