Launch a new console application using the following code -
class Program { static void Main(string[] args) { while (true) { Task<string> readLineTask = Console.In.ReadLineAsync(); Debug.WriteLine("hi"); } } }
Console.In.ReadLineAsync locks and does not return until a line is entered in the console. therefore, "Hello" is never recorded on the console.
Using wait at Console.In.ReadLineAsync also blocks.
I realized that the new Async CTP methods are not blocking.
What is the reason for this?
Here is another example
static void Main(string[] args) { Task delayTask = Task.Delay(50000); Debug.WriteLine("hi"); }
This behaves as I expect, it goes straight to the next line and prints "hello" since Task.Delay is not blocked.
c # async-await
NoPyGod
source share