Home »

How do I use the thread pool?

Question ListCategory: ASP.NETHow do I use the thread pool?
shah_kajal184 author asked 2 years ago
1 Answers
denielshakespeare5 author answered 1 year ago

By passing an instance of a WaitCallback delegate to theThreadPool.QueueUserWorkItem() method
class CApp
{
static void Main(){
string s = “Hello, World”;
ThreadPool.QueueUserWorkItem( new WaitCallback( DoWork ), s );
Thread.Sleep( 1000 ); // Give time for work item to be executed
}
// DoWork is executed on a thread from the thread pool.
static void DoWork( object state ){
Console.WriteLine( state );
}
}

Please login or Register to Submit Answer