Here I have two functions static int Main() and static async Task<int> Main().
Can anyone tell me what is the difference between them?
static int Main()
{
return DoAsyncWork().GetAwaiter().GetResult();
}
static async Task<int> Main()
{
return await DoAsyncWork();
}
and is await.
Async Main is actually not the method that runs first. Compiler generates standard
Mainmethod that calls the async version ofMain:So the difference is that when using
async Main, there are two methods calledMain. One async and one generated by the compiler.Because these two methods have the same name and parameters and only differ by return type, compiler generates method with name
<Main>, notMain. This is the generated signature: