开发者

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

开发者 https://www.devze.com 2023-01-03 17:00 出处:网络
VS2010 Threads window shows 25 threads and Process.Threads.Count.50 What are the other 25 are doing?开发者_Python百科 Anytime you create a thread in user code, the system creates a matching kernel t

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

What are the other 25 are doing?开发者_Python百科


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消