From 864fb53ab60e1a25b10c00c29c1e4f81c9854137 Mon Sep 17 00:00:00 2001 From: RogueException Date: Wed, 11 Nov 2015 20:25:53 -0400 Subject: [PATCH] Dont crash if client is disconnected from within DiscordClient.Run --- src/Discord.Net/DiscordWSClient.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net/DiscordWSClient.cs b/src/Discord.Net/DiscordWSClient.cs index edd361623..4b64200d4 100644 --- a/src/Discord.Net/DiscordWSClient.cs +++ b/src/Discord.Net/DiscordWSClient.cs @@ -257,7 +257,11 @@ namespace Discord /// Blocking call that will not return until client has been stopped. This is mainly intended for use in console applications. public void Run(Func asyncAction) { - asyncAction().Wait(); + try + { + asyncAction().Wait(); + } + catch (AggregateException ex) when (ex.InnerException is TaskCanceledException) { } _disconnectedEvent.WaitOne(); } /// Blocking call that will not return until client has been stopped. This is mainly intended for use in console applications.