Created
November 24, 2017 18:19
-
-
Save jskeet/27e26a97907af2488f0d7d5b0dbe06a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
public class Test | |
{ | |
static void Main() | |
{ | |
Task task = DelayAndPrintAsync(); | |
Console.WriteLine("Task returned to Main. Sleeping for 10s"); | |
Thread.Sleep(10000); | |
Console.WriteLine("Waiting for task to finish"); | |
// Normally you really don't want to use Task.Wait(), but | |
// in a console app's main thread it's okay. | |
task.Wait(); | |
} | |
static async Task DelayAndPrintAsync() | |
{ | |
Console.WriteLine("In DelayAndPrintAsync before first delay"); | |
await Task.Delay(5000); | |
Console.WriteLine("In DelayAndPrintAsync between delays"); | |
await Task.Delay(10000); | |
Console.WriteLine("In DelayAndPrintAsync after second delay"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment