Async code can improve the performance and responsiveness of applications, but there are trade-offs. In the case of GUI-based applications, such as Windows Forms or WPF, if a method is taking a long time, it makes sense to make it async. For server applications, however, you need to measure the trade-off between the extra memory utilized by the blocked threads and the extra processor overhead required to make methods asynchronous.
Consider the following code, which creates three tasks. Each task runs asynchronously, one after another. As one method finishes, it goes on to execute another task asynchronously. The total time taken to finish the method can be calculated using Stopwatch:
public static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
Console.ReadLine();
}
public static async Task MainAsync(string[] args...