mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Use long running task for plugin ctor (#2406)
This commit is contained in:
parent
d61a35b81f
commit
aa3d6c3efe
1 changed files with 8 additions and 20 deletions
|
|
@ -112,27 +112,15 @@ internal class ServiceContainer : IServiceProvider, IServiceType
|
||||||
errorStep = "property injection";
|
errorStep = "property injection";
|
||||||
await this.InjectProperties(instance, scopedObjects, scope);
|
await this.InjectProperties(instance, scopedObjects, scope);
|
||||||
|
|
||||||
|
// Invoke ctor from a separate thread (LongRunning will spawn a new one)
|
||||||
|
// so that it does not count towards thread pool active threads cap.
|
||||||
|
// Plugin ctor can block to wait for Tasks, as we currently do not support asynchronous plugin init.
|
||||||
errorStep = "ctor invocation";
|
errorStep = "ctor invocation";
|
||||||
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
await Task.Factory.StartNew(
|
||||||
var thr = new Thread(
|
() => ctor.Invoke(instance, resolvedParams),
|
||||||
() =>
|
CancellationToken.None,
|
||||||
{
|
TaskCreationOptions.LongRunning,
|
||||||
try
|
TaskScheduler.Default).ConfigureAwait(false);
|
||||||
{
|
|
||||||
ctor.Invoke(instance, resolvedParams);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
tcs.SetException(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tcs.SetResult();
|
|
||||||
});
|
|
||||||
|
|
||||||
thr.Start();
|
|
||||||
await tcs.Task.ConfigureAwait(false);
|
|
||||||
thr.Join();
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue