Async Main
A new feature of language C# 7.1 that enables entry-point that is, Main of an application. Async main enables main method to be awaitable that mean Main method is now asynchronous to get Task or Task<int>. With this feature followings are valid entry-points:
static Task Main()
{
//stuff goes here
}
static Task<int> Main()
{
//stuff goes here
}
static Task Main(string[] args)
{
//stuff goes here
}
static Task<int> Main(string[] args)
{
//stuff goes here
}Restrictions while using new signatures
- You can use these new signature entry-points and these marked as valid if no overload of previous signature is present that means if you are using an existing entry-point.
public static void Main()
{
NewMain().GetAwaiter().GetResult();
}
private static async Task NewMain()
{
//async stuff goes here
}- This is not mandatory to mark your entry-point as async that means you can still use the existing async entry-point:
private static void Main(string[] args...