【发布时间】:2013-02-08 10:48:39
【问题描述】:
我在 Visual Studio 2010、Windows XP SP3 中运行以下 C# 代码。
在“不调试启动”中(按 Ctrl+F5 或从菜单),输出:
- 来自main的你好
工人问好
“开始调试”(按 F5 或从菜单)显示相反的顺序:
- 工人问好
来自主要的你好
检查了很多次。它是可重现和可重复的。
为什么?
using System;
using System.Threading;
namespace _5NamingThreads
{
class ThreadNaming
{
static void Main()
{
Thread.CurrentThread.Name = "main";
Thread worker = new Thread(Go);
worker.Name = "worker";
worker.Start();
Go();
Console.ReadLine();
}
static void Go()
{
Console.WriteLine("Hello from " + Thread.CurrentThread.Name);
}
}
}
更新:
第二天,重新启动计算机后,我总是观察在所有模式下都可以重现的顺序,Release 和 Debug:
- 来自main的你好
工人问好
后续问题:
While debugging, is it possible to ensure the output without stepping into each line of code?
【问题讨论】:
标签: c# multithreading visual-studio debugging release