There are a number of ways to enter the thread pool:
Via the Task Parallel Library (from Framework 4.0)
By calling ThreadPool.QueueUserWorkItem
Via asynchronous delegates
Via BackgroundWorker
The following constructs use the thread pool
indirectly:
· WCF, Remoting, ASP.NET, and ASMX Web Services application servers
· System.Timers.Timer and System.Threading.Timer
· Framework methods that end in Async, such as those on WebClient (the event-based asynchronous pattern),and most BeginXXX methods (the asynchronous programming model pattern)
· PLINQ
There are a few things to be wary of when using pooled threads:
· You cannot set the Name of a pooled thread, making debugging more difficult (although you can attach a description when debugging in Visual Studio’s Threads window).
· Pooled threads are always background threads (this is usually not a problem).
· Blocking a pooled thread may trigger additional latency in the early life of an application unless you call ThreadPool.SetMinThreads (see Optimizing the Thread Pool).
You are free to change the priority of a pooled thread—it will be restored to normal when released back to thepool.
You can query if you’re currently executing on a pooled thread via the property:Thread.CurrentThread.IsThreadPoolThread.
本文转自cnn23711151CTO博客,原文链接:http://blog.51cto.com/cnn237111/510213
,如需转载请自行联系原作者