threads

  • Thread starter Thread starter Tpool
  • Start date Start date
T

Tpool

hi,
How to create the more than 25 threads in threadpool. i tried more than 25
threads in web request, but it shows an error. how can i have my threads to
some 25 or more ,check the status of the threads, and assigning the task to
completed threads in a loop.
Thanks
 
It would help if you did specify exactly what error is shown (call stack)
and some code that illustrates how you 'create' your threads in the pool.

Willy.
 
Tpool,

You shouldn't play around with the threadpool, or the maximum number of
threads that it uses. You are going to absolutely kill performance if you
set the max number of concurrent threads higher.

You can send as many tasks as you want to the thread pool. Is there a
reason you want to execute more than 25 at a time (per processor,
approximately)?
 
Tpool said:
How to create the more than 25 threads in threadpool. i tried more than 25
threads in web request, but it shows an error. how can i have my threads to
some 25 or more ,check the status of the threads, and assigning the task to
completed threads in a loop.

The system thread pool will only contain 25*number of processors
threads, and there's nothing you can easily do about that. However, you
don't need to use the system thread pool to create threads.

See http://www.pobox.com/~skeet/csharp/threads

You can even write your own thread pool without too much difficulty.
 
Jon Skeet said:
The system thread pool will only contain 25*number of processors
threads, and there's nothing you can easily do about that. However, you
don't need to use the system thread pool to create threads.

See http://www.pobox.com/~skeet/csharp/threads

You can even write your own thread pool without too much difficulty.

Jon,

The number of worker threads in the pool is actually "25 per processor per
process", while the number of IOC threads in the pool is 1000 per processor
per process. Note that these are figures valid for V1.1.

Willy.
 
Actually i am creating more because, i want to check the number of urls, it
takes so much time when do this by ordinary methods, so i decided to go with
the threads. Here with attached the sample code. in that i can able to
create threads but unable to assign the task to the completed threads.

thanks in advance
 
Tpool,

I have made the following simple changes (see comments ) ....
obj.CheckUrls();
Console.ReadLine(); //**** Somehow you need to block the main thread,
I've used this for test purposes, but you need to use some other signaling
technique in production code.
}

public void CheckUrls()
{
for(int i =0;i<arr_URLList.Count;i++)
{
//**** Here I removed the workingThreads check as you never decrement this
number you will end executing DoEvents() in an endless loop just burning CPU
cycles, note that you should NEVER call DoEvents() in a non Windows Forms
application.
//**** Also you don't have to limit the work items queued (apart from memory
consumption constraints), this number can be much higher than the number
threads in the pool.
System.Threading.ThreadPool.QueueUserWorkItem(callUrl,(object)arr_URLList);
workingThreads++; // this is the number of queued items, NOT the
number of threads taken from the pool (max 25)
Console.WriteLine("the thread number " + i);
}
}

But I don't like the idea of queuing webrequests against the Workerthread
pool, you should definitely try to use the asynchronous programming model
based on asynch. delegates (see BeginGetResponse in msdn) when executing
network (or any other kind of IO) requests.

Willy.
 
hi nair,

Thanks for the suggestion, i will implement and let you know the results.
Meanwhile do you have any sample codes for this ?.
 
hi,

I am struggling to find the solution, it would be great help if you get some
sample code.

Thanks
 
Back
Top