-
-
Save TaliSoroker/74c09bec78c6ec7d7e9d04fe662e7877 to your computer and use it in GitHub Desktop.
async/await
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
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