This is because the application is complete. You need to wait until AsyncExample is finished before allowing the main one to complete the code.
Currently, the Main method ends before your task completes, and therefore the application immediately terminates, regardless of the state of the tasks.
, , AsyncExample.
: , Task.Wait().
. Result ( , , ).
, , Exception , . .
static async Task AsyncExample()
{
Task<string> task = DownloadPageAsync();
string result = await task;
WriteToFile(result, someFileName);
}
public static void Main(string[] args)
{
var task = AsyncExample();
task.Wait();
}