ThreadPool basically maintain “pool” of threads which are waiting for work items. As thread creation is not a cheap process. By default, the thread pool has 25 threads per processor.

We can Queue up method to the ThreadPool using it’s QueueUserWorkItem method. It takes two parameters – a WaitCallback delegate to the method you want to call and the optional object to pass as parameter to the callback method.

     protected void Page_Load(object sender, EventArgs e)  


            WaitCallback callBack;   

            callBack = new WaitCallback(DoubleMe);  

            ThreadPool.QueueUserWorkItem(callBack, 1);  

            ThreadPool.QueueUserWorkItem(callBack, 2);  

            ThreadPool.QueueUserWorkItem(callBack, 3);  


        public void DoubleMe(int i)  


            // Simulation of processing time   


            String result = (2*i).ToString();

            Response.Write(result + “<BR>”);  


Leave a comment

Filed under C#

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s