A set of technologies in the .NET Framework for building web applications and XML web services.
A few things:
- You don't need the
asyncon the method signature if there's noawaitin the body, so you can drop it from this:
Task.Run(async () => BigAndLongProcessAsync());
- Calling
BigAndLongProcessAsync();without anawaitwill result in all the synchronous code that's executed inBigAndLogProcessAsyncto be run synchronously on the calling thread. If there's anawaitin this method, everything after that line will be executed asynchronously, in a fire-and-forget manner, on a new thread. - Calling your method in a
Task.Runallows you to run the entire method (including the synchronous code that precedes the firstawaitinside your method) on a separate thread.
Whether you use Task.Run depends on whether you want to offload the synchronous work to the separate thread immediately. This may not be ideal as that synchronous code may need to run on the main thread as that thread is the only one that has access to certain resources (e.g. the main thread in Winforms is the thread that you'll want to manipulate UI elements from), in which case your first example would be necessary.