今天有點疑惑就寫了個測試的代碼,發(fā)現(xiàn)控制臺和Winform中不一樣比如:控制臺:...Main(){ Test(); }private static async void Test(){Show("Test.Before");await Task.Run(() => { Thread.Sleep(2000); Show("Test.Task"); });Show("Test.After");//輸出字符串和當前線程}private static void Show(string str){Console.WriteLine($"{str}:{Thread.CurrentThread.ManagedThreadId}\r\n");}輸出:Test.Before:1Test.Task:3Test.After:3 Winform中:...test(){ Test(); }private async void Test(){Show("Test.Before");await Task.Run(() => { Thread.Sleep(2000); });Show("Test.After");//輸出字符串和當前線程}public void Show(string str){richTextBox1.AppendText($"{str}:{Thread.CurrentThread.ManagedThreadId}\r\n");}輸出:Test.Before:1Test.After:1 為什么這兩個不一樣呢?新手求解答
添加回答
舉報
0/150
提交
取消