using System;using System.Threading;namespace NewThreadPoolBehavior{ internal class Program { private static void Main(string[] args) { Console.WriteLine( "Running on " + Environment.Version ); int w, c; ThreadPool.GetMaxThreads( out w, out c ); Console.WriteLine( "Max Currently: " + w + ", " + c ); ThreadPool.GetMinThreads( out w, out c ); Console.WriteLine( "Min Currently: " + w + ", " + c ); Console.WriteLine( "Set min thread count 100? (y/n) " ); string txt = Console.ReadLine(); if ( txt == "y" ) { Console.WriteLine( "Setting min to 100" ); ThreadPool.SetMinThreads( 100, 100 ); ThreadPool.GetMinThreads( out w, out c ); Console.WriteLine( "Min Currently: " + w + ", " + c ); } UseThreadPool( 200 ); Console.ReadLine(); } private static void UseThreadPool(int count) { for ( int i = 0; i < count; i++ ) { ThreadPool.QueueUserWorkItem( delegate { SlowMethod(); } ); } } private static int concurrent = 0; private static void SlowMethod() { concurrent++; Console.WriteLine( "Starting ops (" + concurrent + " concurrent)" ); Thread.Sleep( 20000 ); Console.WriteLine( "Finished ops (" + concurrent + " concurrent)" ); concurrent--; } }}
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u
Page rendered at Friday, July 04, 2008 2:57:56 PM (Eastern Standard Time, UTC-05:00)
Disclaimer These postings are provided "AS IS" with no warranties, and confer no rights.