What version of C# are you using? In later versions (7.1+) of C# Main
can be async so you can await inside Main
just like you would anywhere else.
public static async Task<int> Main(String[] args)
{
await Test();
return 0;
}
For other synchronous methods then you can use a hack.
void SomeSyncMethod ()
{
//Block until done
Test().GetAwaiter().GetResult();
//Alternative version but it doesn't propagate exceptions the same
//Test().Wait();
}
But this is generally not recommended as it can cause issues depending upon how this method is being called. So use it only when you absolutely must.