DailyCoding > General

Using Thread Pool for Multi-Threading application

How to use thread pool for multithreading in a .net application
Author admin on Jun 9, 2008 7 Comments
Rate it    (Rated 3 by 2 people)
71,547 Views

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);
}

C# | Utility | Windows
 

Discussion

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...

Leave a Comment

Name
Email Address
Web Site