I'm calling an async method within my console application. I don't want the app to quit shortly after it starts, i.e. before the awaitable tasks complete. It seems like I can do this:
internal static void Main(string[] args)
{
try
{
Task.WaitAll(DoThisAsync());
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
throw;
}
}
internal static async Task DoThisAsync()
{
//...
}
But according to Stephen Cleary's article it seems like I can't do that and should instead create some kind of context for the async to return to when it's done (e.g. AsyncContext).
The code above works though, and it returns on the main thread after Task.WaitAll(DoThisAsync());
, so why do I need to use a custom context?