Skip to content

Instantly share code, notes, and snippets.

@zs40x
Created Mar 5, 2018
Embed
What would you like to do?
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