Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Run Async methods on MauiProgram.cs

I need to run some async methods that will intercat with db (create admin user, etc). I want to run them on MauiProgram.cs, wondering whats the best way of doing it.The code below works, not sure if its the best way of doing so.

  public static MauiAppBuilder SqlLiteInitializer(this MauiAppBuilder mauiAppBuilder)
  {
      var sqlLite = mauiAppBuilder.Services.BuildServiceProvider().GetRequiredService<ISqlLite<UserModel>>();

      Task.Run(() => sqlLite.CreateOrUpdateTableAsync()).Wait();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Well, async method returns already a task, so it’s just overhead to wrap it in yet anowther, instead you can do:

sqlLite.CreateOrUpdateTableAsync().Wait();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading