From 7e2093e4540505693240b2f62e9ebea52e6d1b8b Mon Sep 17 00:00:00 2001 From: RogueException Date: Sun, 25 Oct 2015 06:30:06 -0300 Subject: [PATCH] Added ConfigureAwait(false) where missing --- src/Discord.Net.Commands/CommandsPlugin.cs | 2 +- src/Discord.Net/DiscordClient.Channels.cs | 4 ++-- src/Discord.Net/DiscordClient.Messages.cs | 2 +- src/Discord.Net/DiscordClient.Permissions.cs | 4 ++-- src/Discord.Net/DiscordClient.Roles.cs | 6 +++--- src/Discord.Net/DiscordClient.Servers.cs | 2 +- src/Discord.Net/DiscordClient.cs | 15 ++++++++------- src/Discord.Net/DiscordWSClient.cs | 10 +++++----- src/Discord.Net/Net/WebSockets/DataWebSocket.cs | 4 ++-- src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs | 2 +- src/Discord.Net/Net/WebSockets/WebSocket.cs | 6 +++--- .../Net/WebSockets/WebSocketSharpEngine.cs | 4 ++-- 12 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/Discord.Net.Commands/CommandsPlugin.cs b/src/Discord.Net.Commands/CommandsPlugin.cs index d9d35f916..44abce8f4 100644 --- a/src/Discord.Net.Commands/CommandsPlugin.cs +++ b/src/Discord.Net.Commands/CommandsPlugin.cs @@ -110,7 +110,7 @@ namespace Discord.Commands { var task = cmd.Handler(eventArgs); if (task != null) - await task; + await task.ConfigureAwait(false); } catch (Exception ex) { diff --git a/src/Discord.Net/DiscordClient.Channels.cs b/src/Discord.Net/DiscordClient.Channels.cs index 86b87c9dd..edae2f010 100644 --- a/src/Discord.Net/DiscordClient.Channels.cs +++ b/src/Discord.Net/DiscordClient.Channels.cs @@ -123,7 +123,7 @@ namespace Discord if (channel == null) throw new ArgumentNullException(nameof(channel)); CheckReady(); - await _api.EditChannel(channel.Id, name: name, topic: topic); + await _api.EditChannel(channel.Id, name: name, topic: topic).ConfigureAwait(false); if (position != null) { @@ -147,7 +147,7 @@ namespace Discord channels[newPos] = channel; } Channel after = minPos > 0 ? channels.Skip(minPos - 1).FirstOrDefault() : null; - await ReorderChannels(channel.Server, channels.Skip(minPos), after); + await ReorderChannels(channel.Server, channels.Skip(minPos), after).ConfigureAwait(false); } } diff --git a/src/Discord.Net/DiscordClient.Messages.cs b/src/Discord.Net/DiscordClient.Messages.cs index a9d91b521..f4f27da7f 100644 --- a/src/Discord.Net/DiscordClient.Messages.cs +++ b/src/Discord.Net/DiscordClient.Messages.cs @@ -187,7 +187,7 @@ namespace Discord CheckReady(); foreach (var message in messages) - await DeleteMessageInternal(message); + await DeleteMessageInternal(message).ConfigureAwait(false); } private async Task DeleteMessageInternal(Message message) { diff --git a/src/Discord.Net/DiscordClient.Permissions.cs b/src/Discord.Net/DiscordClient.Permissions.cs index 02ff32141..34f310947 100644 --- a/src/Discord.Net/DiscordClient.Permissions.cs +++ b/src/Discord.Net/DiscordClient.Permissions.cs @@ -48,7 +48,7 @@ namespace Discord var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != targetId).FirstOrDefault(); if (allowValue != 0 || denyValue != 0) { - await _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allowValue, denyValue); + await _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allowValue, denyValue).ConfigureAwait(false); if (perms != null) { perms.Allow.SetRawValueInternal(allowValue); @@ -68,7 +68,7 @@ namespace Discord { try { - await _api.DeleteChannelPermissions(channel.Id, targetId); + await _api.DeleteChannelPermissions(channel.Id, targetId).ConfigureAwait(false); if (perms != null) { channel.PermissionOverwrites = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != targetId).ToArray(); diff --git a/src/Discord.Net/DiscordClient.Roles.cs b/src/Discord.Net/DiscordClient.Roles.cs index 806aafcbe..09de24c7f 100644 --- a/src/Discord.Net/DiscordClient.Roles.cs +++ b/src/Discord.Net/DiscordClient.Roles.cs @@ -86,7 +86,7 @@ namespace Discord var role = _roles.GetOrAdd(response.Id, server.Id); role.Update(response); - await EditRole(role, name: name); + await EditRole(role, name: name).ConfigureAwait(false); return role; } @@ -101,7 +101,7 @@ namespace Discord name: name ?? role.Name, permissions: permissions?.RawValue ?? role.Permissions.RawValue, color: color?.RawValue, - hoist: hoist); + hoist: hoist).ConfigureAwait(false); if (position != null) { @@ -124,7 +124,7 @@ namespace Discord roles[i] = roles[i - 1]; roles[newPos] = role; } - await _api.ReorderRoles(role.Server.Id, roles.Skip(minPos).Select(x => x.Id), minPos); + await _api.ReorderRoles(role.Server.Id, roles.Skip(minPos).Select(x => x.Id), minPos).ConfigureAwait(false); } } diff --git a/src/Discord.Net/DiscordClient.Servers.cs b/src/Discord.Net/DiscordClient.Servers.cs index 472b43771..1d5228916 100644 --- a/src/Discord.Net/DiscordClient.Servers.cs +++ b/src/Discord.Net/DiscordClient.Servers.cs @@ -99,7 +99,7 @@ namespace Discord if (server == null) throw new ArgumentNullException(nameof(server)); CheckReady(); - var response = await _api.EditServer(server.Id, name: name ?? server.Name, region: region.Value, iconType: iconType, icon: icon); + var response = await _api.EditServer(server.Id, name: name ?? server.Name, region: region.Value, iconType: iconType, icon: icon).ConfigureAwait(false); server.Update(response); } diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index f8ad4e223..f7137dc4c 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -52,7 +52,7 @@ namespace Discord this.Connected += async (s, e) => { _api.CancelToken = CancelToken; - await SendStatus(); + await SendStatus().ConfigureAwait(false); }; VoiceDisconnected += (s, e) => @@ -212,7 +212,7 @@ namespace Discord } catch (TaskCanceledException) { throw new TimeoutException(); } - await Connect(token); + await Connect(token).ConfigureAwait(false); return token; } @@ -227,8 +227,9 @@ namespace Discord _api.Token = token; string gateway = (await _api.Gateway() - .Timeout(_config.APITimeout) - .ConfigureAwait(false)).Url; + .Timeout(_config.APITimeout) + .ConfigureAwait(false) + ).Url; if (_config.LogLevel >= LogMessageSeverity.Verbose) RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, $"Websocket endpoint: {gateway}"); @@ -259,7 +260,7 @@ namespace Discord while (_pendingMessages.TryDequeue(out ignored)) { } } - await _api.Logout(); + await _api.Logout().ConfigureAwait(false); _channels.Clear(); _users.Clear(); @@ -501,7 +502,7 @@ namespace Discord RaiseMessageCreated(msg); if (Config.AckMessages && !isAuthor) - await _api.AckMessage(data.Id, data.ChannelId); + await _api.AckMessage(data.Id, data.ChannelId).ConfigureAwait(false); } break; case "MESSAGE_UPDATE": @@ -612,7 +613,7 @@ namespace Discord //Internal (handled in DiscordSimpleClient) case "VOICE_SERVER_UPDATE": - await base.OnReceivedEvent(e); + await base.OnReceivedEvent(e).ConfigureAwait(false); break; //Others diff --git a/src/Discord.Net/DiscordWSClient.cs b/src/Discord.Net/DiscordWSClient.cs index 6d3549c19..eefc3cc9f 100644 --- a/src/Discord.Net/DiscordWSClient.cs +++ b/src/Discord.Net/DiscordWSClient.cs @@ -77,7 +77,7 @@ namespace Discord { RaiseDisconnected(e); if (e.WasUnexpected) - await socket.Reconnect(_token); + await socket.Reconnect(_token).ConfigureAwait(false); }; if (!_config.VoiceOnly) @@ -90,7 +90,7 @@ namespace Discord } } - socket.ReceivedEvent += async (s, e) => await OnReceivedEvent(e); + socket.ReceivedEvent += async (s, e) => await OnReceivedEvent(e).ConfigureAwait(false); return socket; } internal virtual VoiceWebSocket CreateVoiceSocket() @@ -102,7 +102,7 @@ namespace Discord { RaiseVoiceDisconnected(socket.CurrentServerId, e); if (e.WasUnexpected) - await socket.Reconnect(); + await socket.Reconnect().ConfigureAwait(false); }; if (_config.LogLevel >= LogMessageSeverity.Info) { @@ -212,7 +212,7 @@ namespace Discord catch (Exception ex) { await DisconnectInternal(ex: ex, skipAwait: true).ConfigureAwait(false); } //Ensure all other tasks are signaled to end. - await DisconnectInternal(skipAwait: true); + await DisconnectInternal(skipAwait: true).ConfigureAwait(false); //Wait for the remaining tasks to complete try { await allTasks.ConfigureAwait(false); } @@ -309,7 +309,7 @@ namespace Discord { string token = e.Payload.Value("token"); _voiceSocket.Host = "wss://" + e.Payload.Value("endpoint").Split(':')[0]; - await _voiceSocket.Login(_userId, _dataSocket.SessionId, token, CancelToken); + await _voiceSocket.Login(_userId, _dataSocket.SessionId, token, CancelToken).ConfigureAwait(false); } } break; diff --git a/src/Discord.Net/Net/WebSockets/DataWebSocket.cs b/src/Discord.Net/Net/WebSockets/DataWebSocket.cs index 38f8889e6..49d368748 100644 --- a/src/Discord.Net/Net/WebSockets/DataWebSocket.cs +++ b/src/Discord.Net/Net/WebSockets/DataWebSocket.cs @@ -70,7 +70,7 @@ namespace Discord.Net.WebSockets protected override async Task ProcessMessage(string json) { - await base.ProcessMessage(json); + await base.ProcessMessage(json).ConfigureAwait(false); var msg = JsonConvert.DeserializeObject(json); if (msg.Sequence.HasValue) _lastSeq = msg.Sequence.Value; @@ -104,7 +104,7 @@ namespace Discord.Net.WebSockets Host = payload.Url; if (_logLevel >= LogMessageSeverity.Info) RaiseOnLog(LogMessageSeverity.Info, "Redirected to " + payload.Url); - await Redirect(payload.Url); + await Redirect(payload.Url).ConfigureAwait(false); } } break; diff --git a/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs b/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs index 5a26238a0..8d26276a2 100644 --- a/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs +++ b/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs @@ -66,7 +66,7 @@ namespace Discord.Net.WebSockets if ((WebSocketState)_state == WebSocketState.Connected) { //Adjust the host and tell the system to reconnect - await DisconnectInternal(new Exception("Server transfer occurred."), isUnexpected: false); + await DisconnectInternal(new Exception("Server transfer occurred."), isUnexpected: false).ConfigureAwait(false); return; } diff --git a/src/Discord.Net/Net/WebSockets/WebSocket.cs b/src/Discord.Net/Net/WebSockets/WebSocket.cs index 157923c3f..93ea42ede 100644 --- a/src/Discord.Net/Net/WebSockets/WebSocket.cs +++ b/src/Discord.Net/Net/WebSockets/WebSocket.cs @@ -163,7 +163,7 @@ namespace Discord.Net.WebSockets catch (Exception ex) { await DisconnectInternal(ex: ex, skipAwait: true).ConfigureAwait(false); } //Ensure all other tasks are signaled to end. - await DisconnectInternal(skipAwait: true); + await DisconnectInternal(skipAwait: true).ConfigureAwait(false); //Wait for the remaining tasks to complete try { await allTasks.ConfigureAwait(false); } @@ -186,7 +186,7 @@ namespace Discord.Net.WebSockets _wasDisconnectUnexpected = false; //Dont reset disconnectReason, we may called ThrowError() later - await _engine.Disconnect(); + await _engine.Disconnect().ConfigureAwait(false); _cancelTokenSource = null; var oldState = _state; _state = (int)WebSocketState.Disconnected; @@ -227,7 +227,7 @@ namespace Discord.Net.WebSockets await Task.Delay(_heartbeatInterval, cancelToken).ConfigureAwait(false); } else - await Task.Delay(100, cancelToken); + await Task.Delay(100, cancelToken).ConfigureAwait(false); } } catch (OperationCanceledException) { } diff --git a/src/Discord.Net/Net/WebSockets/WebSocketSharpEngine.cs b/src/Discord.Net/Net/WebSockets/WebSocketSharpEngine.cs index 86cffca47..b892465f0 100644 --- a/src/Discord.Net/Net/WebSockets/WebSocketSharpEngine.cs +++ b/src/Discord.Net/Net/WebSockets/WebSocketSharpEngine.cs @@ -52,14 +52,14 @@ namespace Discord.Net.WebSockets _webSocket.OnError += async (s, e) => { _parent.RaiseOnLog(LogMessageSeverity.Error, e.Exception.GetBaseException().Message); - await _parent.DisconnectInternal(e.Exception, skipAwait: true); + await _parent.DisconnectInternal(e.Exception, skipAwait: true).ConfigureAwait(false); }; _webSocket.OnClose += async (s, e) => { string code = e.WasClean ? e.Code.ToString() : "Unexpected"; string reason = e.Reason != "" ? e.Reason : "No Reason"; Exception ex = new Exception($"Got Close Message ({code}): {reason}"); - await _parent.DisconnectInternal(ex, skipAwait: true); + await _parent.DisconnectInternal(ex, skipAwait: true).ConfigureAwait(false); }; _webSocket.Log.Output = (e, m) => { }; //Dont let websocket-sharp print to console _webSocket.Connect();