Using Thread Pool for Multi-Threading application

Thread pool is basically collection of threads which can be used for preforming task in background. Using thread pool is a good practice over creating a new thread for you task. Whenever the task of a thread from thread pool is completed, then the thread is automatically returned back into the thread queue so that it can be re-used by other asynchronous requests. .NET provides inbuilt support for thread pool. Below is a simple example which will explain how can we use the thread pool.

using System;
using System.Threading;

static void Main()
{
  // Calling MyWaitCallback asynchronously
  ThreadPool.QueueUserWorkItem(MyWaitCallback, 0);
  Console.WriteLine("Please wait while we are processing...");
}

public static void MyWaitCallback(object state)
{
  int threadNo = (int)state;
  
  // Processing code here
  
  Console.WriteLine("Process Completed Thread {0}...", threadNo);
}

10 comment(S)


www.tekresh.ru on May 18, 2010 06:37 PM

Vizit www.tekresh.ru Find everything that you need. the jnly way
The best way to rest.

sanek859 on Apr 20, 2011 06:32 AM


????????????? ????!??????? ???????? ????? ?????????? ?????????
????????? ??????? ???????????? ?? ??? http://www.vipip.ru/index.php?refid=507654




bonus_man on May 13, 2011 11:53 AM

Hello! Open new site!
Http://bonus-soft.ru

kabyh473 on May 15, 2011 10:31 PM

kabuh.ru - ??????? ????! ??????? ??????, ???????????, ?????,???? ? ?????? ?????? ?????????? ?????????! ?? ????? ????? ??????? ?????????? ??????, ??????????? ???????, ????????? ???? ? ?????? ??????!







shamil505 on May 28, 2011 10:01 AM

???"??????????? ????????" ?????????? ???????????? ????? ?? ?????????? ? ??? ???? ????????? ?????? ??????????? ???? ?????? ?????????? ?????? ????? ?????? ? ?????? ?????? ? ????????? ??? ?? ??????? ???????????? ????????????? ?????????
????? ?? ???????????? ????? ????? ??????? ? ???????????? ??????????? ??????? ?????? ? ?????? ??????????? ???????



baklana on Jun 10, 2011 03:46 AM

site-software.ru ?? ????? ?? ?????? ??????? ????,????,??????,?????,????,???? ??? ??????,???????????? PC ??????? ? letitbit ????????? ?????????










bess on Sep 7, 2011 05:42 PM

Wow..I've..never seen such a poorly researched piece of crappy code masquerading as an article supposedly imparting knowledge before this...

User on Jul 25, 2012 12:26 AM

hi dear
using this style in tcp client ,our thread being finsihed in 2-3 days days becoz some thread did not close

so can u give any other solution

thanks
saraswati Pg college

nope on Aug 28, 2012 05:29 AM

?

sponsored

ss on Feb 25, 2013 02:36 AM


Leave a comment