public Task StartAsync(CancellationToken cancellationToken) { logger.LogInformation("Health checks starting."); try { var dbTask = HelperTools.ExecuteWithRetries(10, "Unable to open connection to database", () => TestDBConnection()); Task.WaitAll(new Task[] { dbTask }); logger.LogInformation("Health checks completed successfully."); } catch (Exception ex) { logger.LogError("Health checks failed. {0}", ex.GetBaseException().ToString()); // If exception was thrown then we stop the application. All methods in try section must pass without exception hostApplicationLifetime.StopApplication(); } return(Task.CompletedTask); }