问题
I wrote a small class that executes Main()
, which in turn executes A()
. I expected the Main()
method to be on its own at the root of the stack call, because it's the topmost function in my application. Everything that's done, should be executed by Main()
. I wrote the following code to test that:
namespace ProfilerTest
{
class Program
{
static int _a;
static void Main()
{
while (true)
{
A();
}
}
static void A()
{
_a += 1;
}
}
}
The output of the Profiler Call Tree, however, shows that A()
isn't only executed through Main()
, it's also executed at the same level as the main function.

What I expected (notice I removed the last line from the call tree):
ProfilerTest.exe 10.333
ProfilerTest.Program.Main 10.333
ProfilerTest.Program.A 5.897
Why is this? Is what I'm expecting incorrect? Or do I misinterpret the profiler results?
来源:https://stackoverflow.com/questions/29627551/visual-studio-profiler-output