I’m asking this, because we’re moving our app to service fabric where we no longer can use HostingEnvironment.QueueBackgroundWorkItem(async cancellationToken => await LongMethodAsync()); and the advice is to simply replace it with Task.Run.
That’s bad advice. You should use a separate background process separated from your web frontend by a queue.
What’s the in-depth logic behind the calls?
- Starts the asynchronous method on the current thread. Ignores all results (including exceptions).
- Starts the asynchronous method on the current thread. Asynchronously waits for it to complete. This is the standard way of calling asynchronous code.
- Starts the asynchronous method on a thread pool thread. Ignores all results (including exceptions).
- Starts the asynchronous method on a thread pool thread. Asynchronously waits for it to complete.
- Exactly the same as #3.
- Exactly the same as #4.