One thing that annoys me when debugging programs in Visual Studio (2005 in my case) is that when I use \"step over\" (by pressing F10) to execute to the next line
Apparently, Visual Studio 2010 only switches to other threads if you press F10 when the debugger had to break in that thread before or if a breakpoint is set which will be hit in this thread.
I used the following code to test the behavior:
class Program
{
static void Main(string[] args)
{
var t = new Thread(new ThreadStart(Work));
t.Start();
for (int i = 0; i < 20; i++)
{
Thread.Sleep(1000);
Console.WriteLine("............");
}
t.Join();
}
static void Work()
{
for (int i = 0; i < 20; i++)
{
Thread.Sleep(1000);
Console.WriteLine("ZZzzzzzzzzzzzzzz");
}
}
}
If you just stept to the program or add a breakpoint in the Main()
method, hitting F10 only steps through the code from the main thread.
If you add a breakpoint in the Work()
method, the debugger steps through both threads.
This behavior of Visual Studio makes sense but it all seems like an undocumented feature to me...