Skip to content

Commit

Permalink
Fixed asynchronous DbInitializer.Initialize task
Browse files Browse the repository at this point in the history
  • Loading branch information
reidst committed Dec 11, 2023
1 parent f3896ce commit 62cab0c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.");

0 comments on commit 62cab0c

Please sign in to comment.