From 66fe507b8da8c22e244b4787610cdd441df3f3e4 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 29 Nov 2022 19:02:13 +0000 Subject: [PATCH] Call ConfigureAwait(false) for all awaited tasks --- VpSharp/src/Entities/VirtualParadiseAvatar.cs | 6 ++-- VpSharp/src/Entities/VirtualParadiseUser.cs | 8 ++--- VpSharp/src/Entities/VirtualParadiseWorld.cs | 2 +- .../src/VirtualParadiseClient.NativeEvents.cs | 28 ++++++++--------- VpSharp/src/VirtualParadiseClient.Users.cs | 4 +-- VpSharp/src/VirtualParadiseClient.cs | 30 +++++++++---------- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/VpSharp/src/Entities/VirtualParadiseAvatar.cs b/VpSharp/src/Entities/VirtualParadiseAvatar.cs index 1f42edd..f953171 100644 --- a/VpSharp/src/Entities/VirtualParadiseAvatar.cs +++ b/VpSharp/src/Entities/VirtualParadiseAvatar.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using System.Drawing; using System.Numerics; using VpSharp.Extensions; using VpSharp.Internal; @@ -334,7 +334,7 @@ public sealed class VirtualParadiseAvatar : IEquatable if (isSelf && isNewWorld) { - await _client.EnterAsync(world); + await _client.EnterAsync(world).ConfigureAwait(false); } nint handle = _client.NativeInstanceHandle; @@ -343,7 +343,7 @@ public sealed class VirtualParadiseAvatar : IEquatable { if (!string.IsNullOrWhiteSpace(world)) { - await _client.EnterAsync(world); + await _client.EnterAsync(world).ConfigureAwait(false); } // state change self diff --git a/VpSharp/src/Entities/VirtualParadiseUser.cs b/VpSharp/src/Entities/VirtualParadiseUser.cs index a21d47a..ec79cfb 100644 --- a/VpSharp/src/Entities/VirtualParadiseUser.cs +++ b/VpSharp/src/Entities/VirtualParadiseUser.cs @@ -150,7 +150,7 @@ public sealed class VirtualParadiseUser : IEquatable vp_invite(_client.NativeInstanceHandle, Id, world, x, y, z, (float) yaw, (float) pitch); } - ReasonCode reason = await taskCompletionSource.Task; + ReasonCode reason = await taskCompletionSource.Task.ConfigureAwait(false); return reason switch { ReasonCode.Success => InviteResponse.Accepted, @@ -194,7 +194,7 @@ public sealed class VirtualParadiseUser : IEquatable taskCompletionSource = _client.AddJoinCompletionSource(reference); } - ReasonCode reason = await taskCompletionSource.Task; + ReasonCode reason = await taskCompletionSource.Task.ConfigureAwait(false); Location? location = null; if (reason == ReasonCode.Success) @@ -217,13 +217,13 @@ public sealed class VirtualParadiseUser : IEquatable var position = new Vector3d(x, y, z); var rotation = Quaternion.CreateFromYawPitchRoll(yaw, pitch, 0); - VirtualParadiseWorld world = (await _client.GetWorldAsync(worldName))!; + VirtualParadiseWorld world = (await _client.GetWorldAsync(worldName).ConfigureAwait(false))!; location = new Location(world, position, rotation); if (!suppressTeleport) { - await avatar.TeleportAsync(location.Value); + await avatar.TeleportAsync(location.Value).ConfigureAwait(false); } } diff --git a/VpSharp/src/Entities/VirtualParadiseWorld.cs b/VpSharp/src/Entities/VirtualParadiseWorld.cs index 3151b32..1d1013a 100644 --- a/VpSharp/src/Entities/VirtualParadiseWorld.cs +++ b/VpSharp/src/Entities/VirtualParadiseWorld.cs @@ -126,7 +126,7 @@ public sealed class VirtualParadiseWorld : IEquatable ArgumentNullException.ThrowIfNull(action); var builder = new WorldSettingsBuilder(_client); - await Task.Run(() => action(builder)); + await Task.Run(() => action(builder)).ConfigureAwait(false); builder.SendChanges(); } diff --git a/VpSharp/src/VirtualParadiseClient.NativeEvents.cs b/VpSharp/src/VirtualParadiseClient.NativeEvents.cs index 84b28b0..39b0794 100644 --- a/VpSharp/src/VirtualParadiseClient.NativeEvents.cs +++ b/VpSharp/src/VirtualParadiseClient.NativeEvents.cs @@ -91,7 +91,7 @@ public sealed partial class VirtualParadiseClient { VirtualParadiseAvatar avatar = ExtractAvatar(sender); avatar = AddOrUpdateAvatar(avatar); - avatar.User = await GetUserAsync(vp_int(sender, IntegerAttribute.UserId)); + avatar.User = await GetUserAsync(vp_int(sender, IntegerAttribute.UserId)).ConfigureAwait(false); var args = new AvatarJoinedEventArgs(avatar); RaiseEvent(AvatarJoined, args); @@ -165,7 +165,7 @@ public sealed partial class VirtualParadiseClient session = vp_int(sender, IntegerAttribute.AvatarSession); } - VirtualParadiseObject? virtualParadiseObject = await ExtractObjectAsync(sender); + VirtualParadiseObject? virtualParadiseObject = await ExtractObjectAsync(sender).ConfigureAwait(false); var cell = virtualParadiseObject.Location.Cell; virtualParadiseObject = AddOrUpdateObject(virtualParadiseObject); @@ -174,7 +174,7 @@ public sealed partial class VirtualParadiseClient { if (_cellChannels.TryGetValue(cell, out Channel? channel)) { - await channel.Writer.WriteAsync(virtualParadiseObject); + await channel.Writer.WriteAsync(virtualParadiseObject).ConfigureAwait(false); } } else @@ -202,7 +202,7 @@ public sealed partial class VirtualParadiseClient if (_objects.TryGetValue(objectId, out VirtualParadiseObject? virtualParadiseObject)) { - cachedObject = await ExtractObjectAsync(sender); // data discarded, but used to pull type + cachedObject = await ExtractObjectAsync(sender).ConfigureAwait(false); // data discarded, but used to pull type cachedObject.ExtractFromOther(virtualParadiseObject); virtualParadiseObject.ExtractFromInstance(sender); // update existing instance @@ -233,7 +233,7 @@ public sealed partial class VirtualParadiseClient try { - virtualParadiseObject = await GetObjectAsync(objectId); + virtualParadiseObject = await GetObjectAsync(objectId).ConfigureAwait(false); } catch // any exception: we don't care about GetObject failing. ID is always available { @@ -264,7 +264,7 @@ public sealed partial class VirtualParadiseClient } VirtualParadiseAvatar? avatar = GetAvatar(session); - var virtualParadiseObject = await GetObjectAsync(objectId); + var virtualParadiseObject = await GetObjectAsync(objectId).ConfigureAwait(false); var args = new ObjectClickedEventArgs(avatar, virtualParadiseObject, clickPoint); RaiseEvent(ObjectClicked, args); } @@ -288,7 +288,7 @@ public sealed partial class VirtualParadiseClient if (_worldListChannel is not null) { - await _worldListChannel.Writer.WriteAsync(world); + await _worldListChannel.Writer.WriteAsync(world).ConfigureAwait(false); } } @@ -316,7 +316,7 @@ public sealed partial class VirtualParadiseClient userId = vp_int(sender, IntegerAttribute.FriendUserId); } - VirtualParadiseUser? user = await GetUserAsync(userId); + VirtualParadiseUser? user = await GetUserAsync(userId).ConfigureAwait(false); _friends.AddOrUpdate(userId, user, (_, _) => user); } @@ -438,7 +438,7 @@ public sealed partial class VirtualParadiseClient worldName = vp_string(sender, StringAttribute.TeleportWorld); } - VirtualParadiseWorld? world = string.IsNullOrWhiteSpace(worldName) ? CurrentWorld : await GetWorldAsync(worldName); + VirtualParadiseWorld? world = string.IsNullOrWhiteSpace(worldName) ? CurrentWorld : await GetWorldAsync(worldName).ConfigureAwait(false); var location = new Location(world, position, rotation); VirtualParadiseAvatar? avatar = GetAvatar(session); @@ -458,7 +458,7 @@ public sealed partial class VirtualParadiseClient } VirtualParadiseAvatar? avatar = GetAvatar(session); - var vpObject = await GetObjectAsync(objectId); + var vpObject = await GetObjectAsync(objectId).ConfigureAwait(false); var args = new ObjectBumpEventArgs(avatar, vpObject, BumpPhase.End); RaiseEvent(ObjectBump, args); @@ -500,7 +500,7 @@ public sealed partial class VirtualParadiseClient } VirtualParadiseAvatar? avatar = GetAvatar(session); - var vpObject = await GetObjectAsync(objectId); + var vpObject = await GetObjectAsync(objectId).ConfigureAwait(false); var args = new ObjectBumpEventArgs(avatar, vpObject, BumpPhase.Begin); RaiseEvent(ObjectBump, args); @@ -519,7 +519,7 @@ public sealed partial class VirtualParadiseClient name = vp_string(NativeInstanceHandle, StringAttribute.JoinName); } - VirtualParadiseUser? user = await GetUserAsync(userId); + VirtualParadiseUser? user = await GetUserAsync(userId).ConfigureAwait(false); var joinRequest = new JoinRequest(this, requestId, name, user); var args = new JoinRequestReceivedEventArgs(joinRequest); RaiseEvent(JoinRequestReceived, args); @@ -553,8 +553,8 @@ public sealed partial class VirtualParadiseClient worldName = vp_string(sender, StringAttribute.InviteWorld); } - VirtualParadiseWorld? world = await GetWorldAsync(worldName); - VirtualParadiseUser? user = await GetUserAsync(userId); + VirtualParadiseWorld? world = await GetWorldAsync(worldName).ConfigureAwait(false); + VirtualParadiseUser? user = await GetUserAsync(userId).ConfigureAwait(false); var location = new Location(world, position, rotation); var request = new InviteRequest(this, requestId, avatarName, user, location); diff --git a/VpSharp/src/VirtualParadiseClient.Users.cs b/VpSharp/src/VirtualParadiseClient.Users.cs index 2bcbf58..e0d5a36 100644 --- a/VpSharp/src/VirtualParadiseClient.Users.cs +++ b/VpSharp/src/VirtualParadiseClient.Users.cs @@ -25,7 +25,7 @@ public sealed partial class VirtualParadiseClient if (_usersCompletionSources.TryGetValue(userId, out TaskCompletionSource? taskCompletionSource)) { - return await taskCompletionSource.Task; + return await taskCompletionSource.Task.ConfigureAwait(false); } taskCompletionSource = new TaskCompletionSource(); @@ -36,7 +36,7 @@ public sealed partial class VirtualParadiseClient vp_user_attributes_by_id(NativeInstanceHandle, userId); } - user = await taskCompletionSource.Task; + user = await taskCompletionSource.Task.ConfigureAwait(false); user = AddOrUpdateUser(user); _usersCompletionSources.TryRemove(userId, out TaskCompletionSource? _); diff --git a/VpSharp/src/VirtualParadiseClient.cs b/VpSharp/src/VirtualParadiseClient.cs index 8b1f865..dd7da42 100644 --- a/VpSharp/src/VirtualParadiseClient.cs +++ b/VpSharp/src/VirtualParadiseClient.cs @@ -115,7 +115,7 @@ public sealed partial class VirtualParadiseClient : IDisposable } } - reason = await _connectCompletionSource.Task; + reason = await _connectCompletionSource.Task.ConfigureAwait(false); NoSuccess: switch (reason) @@ -187,8 +187,8 @@ public sealed partial class VirtualParadiseClient : IDisposable /// Connection to the world server timed out. public async Task EnterAsync(string worldName, Vector3d position) { - await EnterAsync(worldName); - await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity); + await EnterAsync(worldName).ConfigureAwait(false); + await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity).ConfigureAwait(false); return CurrentWorld!; } @@ -207,8 +207,8 @@ public sealed partial class VirtualParadiseClient : IDisposable /// Connection to the world server timed out. public async Task EnterAsync(string worldName, Vector3d position, Quaternion rotation) { - await EnterAsync(worldName); - await CurrentAvatar!.TeleportAsync(position, rotation); + await EnterAsync(worldName).ConfigureAwait(false); + await CurrentAvatar!.TeleportAsync(position, rotation).ConfigureAwait(false); return CurrentWorld!; } @@ -226,8 +226,8 @@ public sealed partial class VirtualParadiseClient : IDisposable /// Connection to the world server timed out. public async Task EnterAsync(VirtualParadiseWorld world, Vector3d position) { - await EnterAsync(world); - await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity); + await EnterAsync(world).ConfigureAwait(false); + await CurrentAvatar!.TeleportAsync(position, Quaternion.Identity).ConfigureAwait(false); } /// @@ -245,8 +245,8 @@ public sealed partial class VirtualParadiseClient : IDisposable /// Connection to the world server timed out. public async Task EnterAsync(VirtualParadiseWorld world, Vector3d position, Quaternion rotation) { - await EnterAsync(world); - await CurrentAvatar!.TeleportAsync(position, rotation); + await EnterAsync(world).ConfigureAwait(false); + await CurrentAvatar!.TeleportAsync(position, rotation).ConfigureAwait(false); } /// @@ -263,7 +263,7 @@ public sealed partial class VirtualParadiseClient : IDisposable public async Task EnterAsync(VirtualParadiseWorld world) { ArgumentNullException.ThrowIfNull(world); - await EnterAsync(world.Name); + await EnterAsync(world.Name).ConfigureAwait(false); } /// @@ -305,7 +305,7 @@ public sealed partial class VirtualParadiseClient : IDisposable } } - reason = await _enterCompletionSource.Task; + reason = await _enterCompletionSource.Task.ConfigureAwait(false); NoSuccess: switch (reason) @@ -341,9 +341,9 @@ public sealed partial class VirtualParadiseClient : IDisposable size = vp_int(NativeInstanceHandle, IntegerAttribute.WorldSize); } - await _worldSettingsCompletionSource.Task; + await _worldSettingsCompletionSource.Task.ConfigureAwait(false); - VirtualParadiseWorld? world = await GetWorldAsync(worldName); + VirtualParadiseWorld? world = await GetWorldAsync(worldName).ConfigureAwait(false); if (world is null) { // we entered the world but it wasn't listed. unlisted world. we'll try our best to create details for it @@ -496,7 +496,7 @@ public sealed partial class VirtualParadiseClient : IDisposable } } - reason = await _loginCompletionSource.Task; + reason = await _loginCompletionSource.Task.ConfigureAwait(false); NoSuccess: switch (reason) { @@ -520,7 +520,7 @@ public sealed partial class VirtualParadiseClient : IDisposable userId = vp_int(NativeInstanceHandle, IntegerAttribute.MyUserId); } - CurrentUser = await GetUserAsync(userId); + CurrentUser = await GetUserAsync(userId).ConfigureAwait(false); vp_friends_get(NativeInstanceHandle); }