Async tasks in AfterInitCallbacks


I need to start async tasks after AppHost is initialised.
For now my code is:

public override void Configure(Container container)
    var printerStatusChecker = new PrinterStatusChecker(dbFactory);
    var itlcTcpClient = new ItlcTcpClient(dbFactory);

    AfterInitCallbacks.Add(async host =>
         var printerStatusTask = printerStatusChecker.StartAsync();
         var itlcTcpClientTask = itlcTcpClient.StartAsync();
         await Task.WhenAll(printerStatusTask, itlcTcpClientTask);

Both PrinterStatusChecker and ItlcTcpClient have while(true) { .. } loops inside StartAsync methods and will never finish executing non blocking code inside loop.
Everything seems to working fine, but do you see any problems or maybe better way to start these tasks?

Thank you,

All Startup code in .NET Core or ASP.NET needs to be synchronous so your only option is to block in Startup code like AppHost.Configure().

In general async void should be avoided, at the very least you’ll want to wrap it in a try/catch to prevent any Exceptions taking down the process.