Created
March 5, 2018 10:26
-
-
Save zs40x/a4cd88abbbe3f97224665928ef79fe7d to your computer and use it in GitHub Desktop.
This file contains 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; | |
namespace AsyncTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
new PizzaMaker().MakeAPizza(); | |
Console.WriteLine("Press any key to continue"); | |
Console.ReadKey(); | |
} | |
} | |
internal class PizzaMaker | |
{ | |
public async void MakeAPizza() | |
{ | |
MakeDough(); | |
var task = LetDoughRise(); | |
Log("MuhMuhMuh"); | |
await task; | |
Log("Let's bake :-)"); | |
await Bake(); | |
Log("Serve!"); | |
} | |
private void MakeDough() | |
{ | |
Log("Making dough..."); | |
} | |
private async Task LetDoughRise() | |
{ | |
Log("Waiting for dough to rise"); | |
await Task.Delay(1000); | |
Log("Dough ready"); | |
} | |
private async Task Bake() | |
{ | |
await Task.Delay(1000); | |
} | |
private void Log(string text) | |
{ | |
Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId}: {text}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment