What's the difference between a synchronous void method using Task.Run compared to an asynchronous Task method simply awaiting? I'm torn between which one to use in a web application:
public void CreateScope<T>(Func<T, Task> serviceLayer) where T : class
{
Task.Run(async () =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var scopedService = scope.ServiceProvider.GetRequiredService<T>();
await serviceLayer(scopedService);
}
});
}
or
public async Task CreateScopeAsync<T>(Func<T, Task> serviceLayer) where T : class
{
using (var scope = _serviceScopeFactory.CreateAsyncScope())
{
var scopedService = scope.ServiceProvider.GetRequiredService<T>();
await serviceLayer(scopedService);
}
}
I know Task.Run spins up a new thread but I have limited resources.