get rid of keen threading cringe
All checks were successful
Build / Build Launcher (push) Successful in 2m39s

This commit is contained in:
zznty
2024-05-31 17:22:27 +07:00
parent 9fb29d2011
commit 43a4e6f62b
2 changed files with 16 additions and 25 deletions

View File

@@ -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);
}
}