From 43a4e6f62bed75f72fbc7b0c66143085d67e6a34 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Fri, 31 May 2024 17:22:27 +0700 Subject: [PATCH] get rid of keen threading cringe --- PluginLoader/GUI/MyGuiScreenPluginConfig.cs | 14 +++++------ PluginLoader/SteamAPI.cs | 27 ++++++++------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/PluginLoader/GUI/MyGuiScreenPluginConfig.cs b/PluginLoader/GUI/MyGuiScreenPluginConfig.cs index 2df4de0..00b3771 100644 --- a/PluginLoader/GUI/MyGuiScreenPluginConfig.cs +++ b/PluginLoader/GUI/MyGuiScreenPluginConfig.cs @@ -16,7 +16,6 @@ using VRage.Input; using VRage.Utils; using VRageMath; using static Sandbox.Graphics.GUI.MyGuiScreenMessageBox; -using Parallel = ParallelTasks.Parallel; namespace PluginLoader.GUI; @@ -122,13 +121,12 @@ public class MyGuiScreenPluginConfig : MyGuiScreenBase private void DownloadStats() { - LogFile.Log.Debug("Downloading user statistics", false); - Parallel.Start(() => { PluginStats = StatsClient.DownloadStats(); }, OnDownloadedStats); - } - - private void OnDownloadedStats() - { - pluginDetails?.LoadPluginData(); + LogFile.Log.Debug("Downloading user statistics"); + Task.Run(() => + { + StatsClient.DownloadStats(); + pluginDetails?.LoadPluginData(); + }); } /// diff --git a/PluginLoader/SteamAPI.cs b/PluginLoader/SteamAPI.cs index d6af80a..1cbb059 100644 --- a/PluginLoader/SteamAPI.cs +++ b/PluginLoader/SteamAPI.cs @@ -6,7 +6,6 @@ using Steamworks; using VRage.Game; using VRage.GameServices; using VRage.Utils; -using Parallel = ParallelTasks.Parallel; namespace PluginLoader; @@ -38,28 +37,22 @@ public static class SteamAPI // Source: MyWorkshop.DownloadWorldModsBlocking var result = new MyWorkshop.ResultData(); - var task = Parallel.Start(delegate { result = UpdateInternal(modItems); }); - while (!task.IsComplete) + var task = Task.Run(() => result = UpdateInternal(modItems)); + while (!task.IsCompleted) { MyGameService.Update(); Thread.Sleep(10); } - if (result.Result is not MyGameServiceCallResult.OK) + if (result.Result is MyGameServiceCallResult.OK) return; + + if (task.Exception is not null) { - var exceptions = task.Exceptions; - if (exceptions is { Length: > 0 }) - { - var sb = new StringBuilder(); - sb.AppendLine("An error occurred while updating workshop items:"); - foreach (var e in exceptions) - sb.Append(e); - LogFile.Log.Debug(sb.ToString()); - } - else - { - LogFile.Log.Debug("Unable to update workshop items"); - } + LogFile.Log.Error(task.Exception, "An error occurred while updating workshop items"); + } + else + { + LogFile.Log.Error("Unable to update workshop items due to {Result}", result.Result); } }