0% found this document useful (0 votes)
5 views2 pages

Pizzaasync

The document contains an asynchronous C# program that simulates preparing a pizza by heating the oven and preparing the pizza itself. It includes methods for various tasks such as getting a frozen pizza, opening the pizza box, and checking if the oven is ready, utilizing async/await for non-blocking operations. The program outputs messages to the console at each step of the process, demonstrating the use of asynchronous programming in a cooking scenario.

Uploaded by

chloekhoury2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Pizzaasync

The document contains an asynchronous C# program that simulates preparing a pizza by heating the oven and preparing the pizza itself. It includes methods for various tasks such as getting a frozen pizza, opening the pizza box, and checking if the oven is ready, utilizing async/await for non-blocking operations. The program outputs messages to the console at each step of the process, demonstrating the use of asynchronous programming in a cooking scenario.

Uploaded by

chloekhoury2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

internal class Program

{
static async Task Main(string[] args)
{
Console.WriteLine("Hello, Sync vs Async!");
//PrePrareOven();
var readyoven = await PrePrareOvenAsync();
var preparePizza = await preparePizzaAsync();
Console.WriteLine(readyoven);
Console.WriteLine(preparePizza);
grabABeverage();
watchTV();
}
private static async Task<string> preparePizzaAsync()
{
getFrozenPizza();
openFrozenPizza();
getPizzaPan();
placeFrozenPizzaOnPan();
await Task.Delay(10000);
return "Put in oven";
}
private static void watchTV()
{
Console.WriteLine("Watching Television");
}

private static void placeFrozenPizzaOnPan()


{
Console.WriteLine("Putting Pizza in Pan");
}

private static void grabABeverage()


{
Console.WriteLine("Getting Somthing To drink");
}
private static void getPizzaPan()
{
Console.WriteLine("Getting Pizza Pan");
}
private static void openFrozenPizza()
{
Console.WriteLine("Opening the Pizza Box ");
}

private static void getFrozenPizza()


{
Console.WriteLine("Getting Pizza From Fidge");
}

//private static void PrePrareOven()


//{
// Console.WriteLine("Begin to heat the oven");
// var response = OvenReady();
// Console.WriteLine(response);
//}
private static async Task<string> PrePrareOvenAsync()
{
Console.WriteLine("Begin to heat the oven");
Console.WriteLine($"asynchronously on thread
{Thread.CurrentThread.ManagedThreadId}...");
var Ovensignal = OvenReadyAsync();
var signal = await Ovensignal;
Console.WriteLine("Getting the oven PrePrared");
Console.WriteLine($"asynchronously on thread
{Thread.CurrentThread.ManagedThreadId}...");
string ret = $"Today is {DateTime.Today:D}\n" +
"Oven ready at hours : " +
$"{signal}";
return ret;
}
//private static string OvenReady()
//{
// Thread.Sleep(10000);
// //Task.Delay(10000).Wait();
// return "Beep the oven is ready at the right temperature !";
//}

static async Task<string> OvenReadyAsync()


{
Console.WriteLine("Getting the oven ready");
Console.WriteLine($"asynchronously on thread
{Thread.CurrentThread.ManagedThreadId}...");
await Task.Delay(10000);
Console.WriteLine("oven ready");
Console.WriteLine($"asynchronously on thread
{Thread.CurrentThread.ManagedThreadId}...");
var today = await
Task.FromResult<string>(DateTime.Now.DayOfWeek.ToString());
//Trace.WriteLine(DateTime.Now.DayOfWeek.ToString());
return ($"Beep the oven is ready at the right temperature for
{today} !");
}
}

You might also like