Search code examples
c#wpfmultithreadingthreadpool

What threads are used in a WPF application?


I'm looking to understand the thread usage in various types of applications and I'm a bit surprised that WPF apps have 2 more threads (besides the UI thread) that I didn't expect.

I followed these steps:

  1. create new WPF app
  2. press F5 to start it in debug mode
  3. go to Debug -> Windows -> Parallel Stacks
  4. press Break All button
  5. investigate the Parallel Stacks window

I expected to get a single thread - the UI thread, but got 3 threads instead:

WPF default threads

The leftmost thread is the UI thread - which I expected all along, but what are the other 2 threads used for? I didn't create them - I just made a barebones WPF app - no modifications to the initial code generated by the new project wizard.

Also how do I use the functions indicated with red arrows in the screenshot above:

  1. ProtocolHandler.SendThread
  2. ProtocolHandler.ReadThread

I looked for the documentation, but didn't find much info on these. I also tried to use them in the code behind, but there are no using statements to add - they are just unrecognized.


Solution

  • The full namespace of the ProtocolHandler class is Microsoft.VisualStudio.DesignTools.WpfTap.Networking. As the name indicates, it's used by the design debugging tools from Visual Studio (likely the one that allows to inspect/modify the UI at runtime).

    If you disable those tools in Visual Studio (Tools -> Options -> Debugging -> Uncheck "Enable UI Debugging Tools for XAML"), you'll see that the two extra threads won't be started anymore.