Skip to content

Instantly share code, notes, and snippets.

@zs40x
Created March 5, 2018 10:26
Show Gist options
  • Save zs40x/a4cd88abbbe3f97224665928ef79fe7d to your computer and use it in GitHub Desktop.
Save zs40x/a4cd88abbbe3f97224665928ef79fe7d to your computer and use it in GitHub Desktop.
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