From bfc91fc01548389bbebf95819067bdd591356c58 Mon Sep 17 00:00:00 2001 From: laolarou Date: Tue, 5 Nov 2024 23:00:24 +0800 Subject: [PATCH] use better task wait --- .../DefaultComponent/Authenticator/MicrosoftAuthenticator.cs | 2 +- .../DefaultComponent/Authenticator/OfflineAuthenticator.cs | 2 +- .../DefaultComponent/Authenticator/YggdrasilAuthenticator.cs | 2 +- .../ProjBobcat/DefaultComponent/DefaultResourceCompleter.cs | 2 +- .../ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs | 2 +- .../Installer/ForgeInstaller/HighVersionForgeInstaller.cs | 2 +- .../Installer/ForgeInstaller/LegacyForgeInstaller.cs | 2 +- .../DefaultComponent/Installer/LiteLoaderInstaller.cs | 2 +- .../Installer/ModPackInstaller/CurseForgeInstaller.cs | 2 +- .../Installer/ModPackInstaller/ModrinthInstaller.cs | 2 +- .../ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs | 2 +- .../ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs | 2 +- .../ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs | 2 +- .../DefaultComponent/ResourceInfoResolver/ResolverBase.cs | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs index fc5acb4..ae38c49 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs @@ -66,7 +66,7 @@ public MicrosoftAuthenticator() public AuthResultBase Auth(bool userField = false) { - return AuthTaskAsync(userField).Result; + return AuthTaskAsync(userField).GetAwaiter().GetResult(); } public async Task AuthTaskAsync(bool userField = false) diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs index 0182db1..1149db8 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/OfflineAuthenticator.cs @@ -110,7 +110,7 @@ public AuthResultBase Auth(bool userField = false) /// public Task AuthTaskAsync(bool userField) { - return Task.Run(() => Auth()); + return Task.FromResult(Auth()); } /// diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs index 91b6602..4310b27 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs @@ -81,7 +81,7 @@ public class YggdrasilAuthenticator : IAuthenticator /// public AuthResultBase Auth(bool userField = false) { - return AuthTaskAsync().Result; + return AuthTaskAsync().GetAwaiter().GetResult(); } /// diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/DefaultResourceCompleter.cs b/ProjBobcat/ProjBobcat/DefaultComponent/DefaultResourceCompleter.cs index 77a516c..51837ac 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/DefaultResourceCompleter.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/DefaultResourceCompleter.cs @@ -35,7 +35,7 @@ public class DefaultResourceCompleter : IResourceCompleter public TaskResult CheckAndDownload() { - return CheckAndDownloadTaskAsync().Result; + return CheckAndDownloadTaskAsync().GetAwaiter().GetResult(); } public async Task> CheckAndDownloadTaskAsync() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs index 6bd6cc8..b950315 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs @@ -19,7 +19,7 @@ public class FabricInstaller : InstallerBase, IFabricInstaller public string Install() { - return InstallTaskAsync().Result; + return InstallTaskAsync().GetAwaiter().GetResult(); } public async Task InstallTaskAsync() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs index 36a6cc9..cd2046c 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs @@ -44,7 +44,7 @@ public partial class HighVersionForgeInstaller : InstallerBase, IForgeInstaller public ForgeInstallResult InstallForge() { - return InstallForgeTaskAsync().Result; + return InstallForgeTaskAsync().GetAwaiter().GetResult(); } ForgeInstallResult GetCorruptedFileResult() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs index 0b3b05e..4bf6921 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs @@ -34,7 +34,7 @@ public string DownloadUrlRoot public ForgeInstallResult InstallForge() { - return InstallForgeTaskAsync().Result; + return InstallForgeTaskAsync().GetAwaiter().GetResult(); } public async Task InstallForgeTaskAsync() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs index 9a5f8cc..91e69ab 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs @@ -25,7 +25,7 @@ public class LiteLoaderInstaller : InstallerBase, ILiteLoaderInstaller public string Install() { - return InstallTaskAsync().Result; + return InstallTaskAsync().GetAwaiter().GetResult(); } public async Task InstallTaskAsync() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs index e4bf4dc..a988f53 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/CurseForgeInstaller.cs @@ -25,7 +25,7 @@ public sealed class CurseForgeInstaller : ModPackInstallerBase, ICurseForgeInsta public void Install() { - InstallTaskAsync().Wait(); + InstallTaskAsync().GetAwaiter().GetResult(); } public static async Task<(string? FileName, string? Url)> TryGuessModDownloadLink(long fileId) diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs index d977cfa..6748fc8 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModrinthInstaller.cs @@ -38,7 +38,7 @@ public sealed class ModrinthInstaller : ModPackInstallerBase, IModrinthInstaller public void Install() { - InstallTaskAsync().Wait(); + InstallTaskAsync().GetAwaiter().GetResult(); } public async Task InstallTaskAsync() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs index 7b59b1f..8ead501 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs @@ -24,7 +24,7 @@ public class OptifineInstaller : InstallerBase, IOptifineInstaller public string Install() { - return InstallTaskAsync().Result; + return InstallTaskAsync().GetAwaiter().GetResult(); } public async Task InstallTaskAsync() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs index 2356183..58c2ae2 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs @@ -25,7 +25,7 @@ public class QuiltInstaller : InstallerBase, IQuiltInstaller public string Install() { - return InstallTaskAsync().Result; + return InstallTaskAsync().GetAwaiter().GetResult(); } public async Task InstallTaskAsync() diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs index 42d995d..4189598 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/GameCore/GameCoreBase.cs @@ -46,7 +46,7 @@ public event EventHandler LaunchLogEventDelegate /// public virtual LaunchResult Launch(LaunchSettings settings) { - return LaunchTaskAsync(settings).Result; + return LaunchTaskAsync(settings).GetAwaiter().GetResult(); } /// diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs index c09983a..55906bc 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/ResolverBase.cs @@ -28,7 +28,7 @@ public event EventHandler GameResourceInfoReso public virtual IEnumerable ResolveResource() { - return ResolveResourceAsync().ToListAsync().Result; + return ResolveResourceAsync().ToListAsync().GetAwaiter().GetResult(); } public void Dispose()