Isolate plugin constructors to separate threads

This commit is contained in:
Soreepeong 2024-07-21 15:30:22 +09:00
parent 8ca473839a
commit d16e783466

View file

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Logging.Internal;
@ -127,7 +128,26 @@ internal class ServiceContainer : IServiceProvider, IServiceType
return null;
}
ctor.Invoke(instance, resolvedParams);
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var thr = new Thread(
() =>
{
try
{
ctor.Invoke(instance, resolvedParams);
}
catch (Exception e)
{
tcs.SetException(e);
return;
}
tcs.SetResult();
});
thr.Start();
await tcs.Task.ConfigureAwait(false);
thr.Join();
return instance;
}