Last active
August 29, 2015 13:56
-
-
Save joeriks/9092236 to your computer and use it in GitHub Desktop.
C# async await the most basic example
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
| async Task slowTask(){ | |
| await Task.Delay(1000); | |
| Console.WriteLine("Prints after 1 second"); | |
| } | |
| void Main() | |
| { | |
| slowTask(); | |
| Console.WriteLine("Prints immediately"); | |
| } |
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
| void slowTask(){ | |
| Console.WriteLine("Prints after"); | |
| } | |
| void Main() | |
| { | |
| Task.Run(()=>slowTask()); | |
| Console.WriteLine("Prints immediately"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment