views:

48

answers:

2

VS2010 Threads window shows 25 threads and Process.Threads.Count.50

What are the other 25 are doing?

+1  A: 

Probably the thread pool. The thread pool will create a bunch of threads for you so that when you use them you don't have to incur the cost of spinning up the new thread at that moment.

One way to run things in the thread pool is to create a delegate and call BeginInvoke on it. Such as:

var a = new System.Action(() => { /* do work in the background! */ });
a.BeginInvoke(r => a.EndInvoke(r), null);

The body of the action will be executed in one of those threads.

justin.m.chase
+1  A: 

Anytime you create a thread in user code, the system creates a matching kernel thread. My guess (though it's certainly only a guess) is that one of the tools is showing the count only of user threads, while the other shows the count for both user and kernel threads.

Jerry Coffin
no. task manager shows only unmanaged threads.
Bobb