Make ServiceScope IAsyncDisposable

ServiceScope.Dispose was not waiting for scoped services to complete
disposing. This had an effect of letting a new plugin instance register
a DtrBar entry before previous plugin instance's entry got unregistered.

This change also cleans up unloading procedure in LocalPlugin.
This commit is contained in:
Soreepeong 2024-08-18 07:58:45 +09:00
parent fdfdee1fcb
commit 0a8f9b73fb
7 changed files with 375 additions and 184 deletions

View file

@ -63,6 +63,21 @@ public static class TaskExtensions
#pragma warning restore RS0030
}
/// <summary>Ignores any exceptions thrown from the task.</summary>
/// <param name="task">Task to ignore exceptions.</param>
/// <returns>A task that completes when <paramref name="task"/> completes in any state.</returns>
public static async Task SuppressException(this Task task)
{
try
{
await task;
}
catch
{
// ignore
}
}
private static bool IsWaitingValid(Task task)
{
// In the case the task has been started with the LongRunning flag, it will not be in the TPL thread pool and we can allow waiting regardless.