i`v was studying asynchronous proging in .net today and I realized that this code should NOT create a new thread, but I see different ThreadId with a call to Thread.CurrentThread.ManagedThreadId.
static void Main(string[] args)
{
Do();
Console.WriteLine("Main {0}",Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(400);
}
private static async void Do()
{
Task<string> task = new StreamReader(@"D:\a.txt").ReadLineAsync();
string result = await task;
Console.WriteLine("DO {0}", Thread.CurrentThread.ManagedThreadId);
}
Thank you all for this.
source
share