Search 
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 4 Comments
Rate it    (Rated 5 by 1 people)
25,281 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

waresites On Mar 19, 2010 10:26 AM
??????? ? ?????? ???????? ????? ????? ???? <a href=>http://lifesoft.info</a>
?? ????? ?? ?????? ??????? ????????? ??????,????,????????? ? ?????? ??????.



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.

hotprice129 On Jun 23, 2010 04:58 PM
?????? HOTPRICE.UA ? ??? ????? ?????? ??????? ??????? ? ??? ?? ?????? ???????? ??????????? ?? ???? ???????? ???????. ??????? ????????? ?? ????????? ???????????. ??????? ????? ? ?????????, ???????? ??????? ?????? ?? ????????? ????????? (????????????, ?????? ?????????????, ????) ? ??? ??? ?????? ??? ??????? ????????? ?????? ?????? ? ????????. <a href=http://hotprice.ua/>Hot Price</a>.







bill20N On Jul 5, 2010 09:11 AM
???????? ????? ???? ?????? ?? <a href=http://countrywarez.ru></a> ?? ????? ?? ???????
?????? ?????? ????????? ???? ????? ?????? ? ??? ?? ????? ???? ??? !



Leave a Comment

Name
Email Address
Web Site
© Copyright 2008 Daily Coding • All rights reserved