I am profiling a colleague's C# application. The VS2015 analysis tool shows that 33% of exclusive samples occur in System.Windows.Forms.Application.Run. Nearly all of the computation occurs inside a click event, and the form is unresponsive as you would expect. I searched through the code to make sure no threads were being created explicitly.
I was trying to figure out where that 33% was being used. When I stop the application randomly, it's always in windowThreadProc (file SystemEvents.cs) waiting on messages. I can step through the loop even as the main computation is running; so, it's clearly on a separate thread.
The function EnsureSystemEvents is run before Main. I can step through it and see it's spinning up a thread for windowThreadProc. I can see the [STAThread] attribute above Main.
Shouldn't there be only one thread? Please explain.