Skip to content

Commit

Permalink
trying test
Browse files Browse the repository at this point in the history
  • Loading branch information
Simnico99 committed Jan 11, 2023
1 parent 655ca5d commit 4383435
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/ZirconNet.WPF/Hosting/Lifetime/UseWpfApplicationLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,15 @@ public static Task RunWpfApplicationAsync<T>(this IHostBuilder builder, Action<W
return RunWpfApplicationAsyncInternal<T>(builder, cancellationToken);
}

private static Task RunWpfApplicationAsyncInternal<T>(IHostBuilder builder, CancellationToken cancellationToken) where T : Window
private async static Task RunWpfApplicationAsyncInternal<T>(IHostBuilder builder, CancellationToken cancellationToken) where T : Window
{
builder.ConfigureServices(services => services.AddSingleton<T>());

using var host = builder.Build();
var window = host.Services.GetRequiredService<T>();

var startTask = host.StartAsync(cancellationToken);
var dialogTask = window.ShowDialogAsync();
var stopTask = host.StopAsync();
host?.Dispose();

return Task.Factory.ContinueWhenAll(new Task[] { startTask, dialogTask, stopTask }, async (tasks) => { foreach (var task in tasks) { await task; } });
await host.StartAsync(cancellationToken);
await window.ShowDialogAsync();
await host.StopAsync();
}
}

0 comments on commit 4383435

Please sign in to comment.