From 80042a7d87d08ea30bfad17e1226fecbb5e6506e Mon Sep 17 00:00:00 2001 From: Loporrit <141286461+loporrit@users.noreply.github.com> Date: Sun, 9 Feb 2025 13:29:52 +0000 Subject: [PATCH] HostBuilder refactor --- MareSynchronos/Plugin.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 05a3924..412b108 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -32,8 +32,7 @@ namespace LoporritSync; public sealed class Plugin : IDalamudPlugin { - private readonly CancellationTokenSource _pluginCts = new(); - private readonly Task _hostBuilderRunTask; + private readonly IHost _host; public static Plugin Self; public Action _realOnFrameworkUpdate = null; @@ -51,7 +50,7 @@ public sealed class Plugin : IDalamudPlugin INotificationManager notificationManager, ITextureProvider textureProvider, IContextMenu contextMenu, IGameInteropProvider gameInteropProvider) { Plugin.Self = this; - _hostBuilderRunTask = new HostBuilder() + _host = new HostBuilder() .UseContentRoot(pluginInterface.ConfigDirectory.FullName) .ConfigureLogging(lb => { @@ -172,14 +171,14 @@ public sealed class Plugin : IDalamudPlugin collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); }) - .Build() - .RunAsync(_pluginCts.Token); + .Build(); + + _ = _host.StartAsync(); } public void Dispose() { - _pluginCts.Cancel(); - _pluginCts.Dispose(); - _hostBuilderRunTask.Wait(); + _host.StopAsync().GetAwaiter().GetResult(); + _host.Dispose(); } }