Skip to content

Instantly share code, notes, and snippets.

@TaliSoroker
Created July 25, 2017 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TaliSoroker/74c09bec78c6ec7d7e9d04fe662e7877 to your computer and use it in GitHub Desktop.
Save TaliSoroker/74c09bec78c6ec7d7e9d04fe662e7877 to your computer and use it in GitHub Desktop.
async/await
class Program
{
public static void Main()
{
Console.WriteLine("Hey David, How much is 98745 divided by 7?");
Task<int> david = ThinkAboutIt();
Console.WriteLine("While he thinks, lets chat about the weather for a bit.");
Console.WriteLine("Do you think it's going to rain tomorrow?");
Console.WriteLine("No, I think it should be sunny.");
david.Wait();
var davidsAnswer = david.Result;
Console.WriteLine($"David: {davidsAnswer}");
Console.ReadKey();
}
private static async Task<int> ThinkAboutIt()
{
await ReadTheManual();
Console.WriteLine("Think I got it.");
return (98745 / 7);
}
private static async Task ReadTheManual()
{
string file = @"D:\HowToCalc.txt";
Console.WriteLine("Reading a manual.");
using (StreamReader reader = new StreamReader(file))
{
string text = await reader.ReadToEndAsync();
}
Console.WriteLine("Done.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment