3 Replies
await Task.WhenAll(Job1(serviceProvider), Job2(serviceProvider));
but keep in mind Job1/Job2 will run synchronously up until their await, you can do an early switch to asynchronous using await Task.Yield();
inside themthanks
A little unrelated styling note, generally you should try to avoid any instance of the service provider inside the code after you have set up your DI registrations. When you have registered everything you should get your services, such as the AppDbContext in this case, from DI injection or factories. Never pass the service provider. The main reason is testability and the ability to mock/inject testable instances, which a provider is not able to do.
Again, unrelated and perhaps not even as applicable here, but I notice you pass the provider into your jobs, and instead you might want to look into instantiating a job class for each job, and pass the referenced through the constructor if you want to support a varying number of parameters.