Async Main() is available, but hidden
How did I miss this?
I love C# and I try to keep up with the latest features. What I didn’t realize until recently is that the C# 7.1 features are already released. And C# 7.1 includes asynchronous Main methods. Awesome!
By default, new projects in Visual Studio only work with the latest major version of the language (which would be 7.0), but you can change that. So, if you try something like this
you will get this compiler error because Main methods are not allowed to be async (until C# 7.1)
“error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater.”
But… open the properties page for your project and click the Advanced button on the Build tab (you might have to scroll down to see it)
and you’ll see the setting to select which compiler version to use. Change “language version” from “latest major version” to “latest minor version”
If you have Visual Studio 2017 v15.3 or later, you the latest version will be C# 7.1. You will now be able to compile and run code with asynchronous Main methods. Plus you will get all the other goodies that have been added to C# recently.
If you are interested in C# language features, you can track their progress at the C# language design repo on GitHub
The sample code above is available as a gist.