From 62cab0c971dbf816f2dceeaf34b9936909dc2eb4 Mon Sep 17 00:00:00 2001 From: reidst Date: Mon, 11 Dec 2023 11:18:54 -0600 Subject: [PATCH] Fixed asynchronous DbInitializer.Initialize task --- Program.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Program.cs b/Program.cs index 250b4b2..57959aa 100644 --- a/Program.cs +++ b/Program.cs @@ -68,10 +68,7 @@ Console.WriteLine("[DebugLog][Program] Ensuring database has been created..."); context.Database.EnsureCreated(); } -Console.WriteLine("[DebugLog][Program] Services have been initialized."); - -Console.WriteLine("[DebugLog][Program] Starting asynchronous DbInitializer.Initialize(ISeeGreenContext)..."); -Task _seedTask = DbInitializer.InitializeAsync(app); +Console.WriteLine("[DebugLog][Program] Services have been initialized, continuing WebApplication initialization..."); app.UseHttpsRedirection(); app.UseStaticFiles(); @@ -82,5 +79,13 @@ app.MapRazorPages(); -Console.WriteLine("[DebugLog][Program] Running WebApplication..."); -app.Run(); +Console.WriteLine("[DebugLog][Program] Synchronous initialization completed, starting WebApplication.Run task..."); +Task appRun = Task.Run(() => app.Run()); + +Console.WriteLine("[DebugLog][Program] Starting DbInitializer.Initialize task..."); +Task seedTask = Task.Run(() => DbInitializer.InitializeAsync(app)); + +Console.WriteLine("[DebugLog][Program] Waiting for both DbInitializer.Initialize and WebApplication.Run to complete..."); +Task.WaitAll(appRun, seedTask); + +Console.WriteLine("[DebugLog][Program] All tasks finished, end of program."); \ No newline at end of file