Main method is main entry point of Program in C#. Main method usually comes in following flavors (overloads):
public static void Main(string[] args);
public static int Main(string[] args);
public static void Main();
public static int Main();
The 'int' ones are ones generally used in native world where the return value needs to be evaluated.
Now, coming to the 'async main'. Following is invalid:
public static async Task Main(string[] args)
and will throw a compile time error:
Program does not contain a static 'Main' method suitable for an entry
point
A workaround is either to call Wait or async wait on an operation.
Either:
public static void Main(string[] args)
{
BuildWebHost(args).RunAsync().GetAwaiter().GetResult();
}
Or:
public static void Main(string[] args)
{
BuildWebHost(args).RunAsync().Wait();
}
Personally, I feel async main is more of a candy. Async main or Main with async just makes asynchronous operations easy to run from the main entry of the program.
Reference here: https://blogs.msdn.microsoft.com/mazhou/2017/05/30/c-7-series-part-2-async-main/