Getting ready for “Async Main” for C#

Here is the MD for Async Main https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.1/async-main.md

The problem is, you want to code for it now, so that you don’t have a pain to update lots of code later. The solution is add it now, sorta.

public class Program
{
    public static void Main(string[] args) => _main(args).Wait();
    public static async Task _main(string[] args)
    {
    // Your code here. 
    }
}

See that? Just have your main code call _main, which _main is the async code. Then you can do a search and replace to clean all that up as needed later, when you switch to C# 7.1 and have Async Main in your C# toolset. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.