今天有点疑惑就写了个测试的代码,发现控制台和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
提交
取消