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 9 2328
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" <an*******@discussions.microsoft.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl... 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
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)?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Tpool" <an*******@discussions.microsoft.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl... 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
Tpool <an*******@discussions.microsoft.com> wrote: 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 - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Tpool <an*******@discussions.microsoft.com> wrote: 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 - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
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
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:Ot**************@TK2MSFTNGP10.phx.gbl... 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" <an*******@discussions.microsoft.com> wrote in message news:eB**************@TK2MSFTNGP09.phx.gbl... 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
Hmm... I see no code in the attachment.
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(call Url,(object)arr_URLList[i]);
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.
"Tpool" <an*******@discussions.microsoft.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl... sorry for the mistake i attached again.
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message news:uO**************@TK2MSFTNGP12.phx.gbl... Hmm... I see no code in the attachment.
hi nair,
Thanks for the suggestion, i will implement and let you know the results.
Meanwhile do you have any sample codes for this ?.
"Nair" <Na**@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com... Hi TP,
Here is what I have done once.
It is better even if you want to create more than 25 threads, keep the thread control in your program
1. Create a thread array of how many you want. Lets say we need to create only 35 threads. 2. As an when the job needs to be done, trigger a thread and increase the running thread to 1. 3. In the thread callback, once the thread is done decrease the counter back to one (Make sure the increasing and decreasing is under lock) 4. Before submitting the job to be trigger check and see if there are threads available to trigger if not put the job in a queue. 5. Add a timer and let the timer wake up every 2 minutes or so (It should be fined tuned based on the job executing time). It should check the trigger array to see if there are threads available to execute. If there are then dequeue the job and submit it for execution.
With this approach, you handle the maximum list and control the job execution as well. If you have any questions please let me know. Thanks. Nair
"Nair" wrote:
HI Tp,
Just curious why do you want to create more than 25 threads? Also how many processors are in the system you are trying? If it is a single processor and it is not a dedicated system to do what you are trying to do, then I would suggest not to do that.
Thanks.
"Tpool" wrote:
> 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 > > >
hi,
I am struggling to find the solution, it would be great help if you get some
sample code.
Thanks
"Nair" <Na**@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com... I am at home, I will try to send a sample code this evening or tomorrow morning. Thanks.
"Tpool" wrote:
hi nair,
Thanks for the suggestion, i will implement and let you know the results. Meanwhile do you have any sample codes for this ?.
"Nair" <Na**@discussions.microsoft.com> wrote in message news:A7**********************************@microsof t.com... > Hi TP, > > Here is what I have done once. > > It is better even if you want to create more than 25 threads, keep the > thread control in your program > > 1. Create a thread array of how many you want. Lets say we need to > create > only 35 threads. > 2. As an when the job needs to be done, trigger a thread and increase > the > running thread to 1. > 3. In the thread callback, once the thread is done decrease the counter > back > to one (Make sure the increasing and decreasing is under lock) > 4. Before submitting the job to be trigger check and see if there are > threads available to trigger if not put the job in a queue. > 5. Add a timer and let the timer wake up every 2 minutes or so (It > should > be > fined tuned based on the job executing time). It should check the > trigger > array to see if there are threads available to execute. If there are > then > dequeue the job and submit it for execution. > > With this approach, you handle the maximum list and control the job > execution as well. If you have any questions please let me know. > Thanks. > Nair > > "Nair" wrote: > >> HI Tp, >> >> Just curious why do you want to create more than 25 threads? Also how >> many >> processors are in the system you are trying? If it is a single >> processor >> and >> it is not a dedicated system to do what you are trying to do, then I >> would >> suggest not to do that. >> >> Thanks. >> >> "Tpool" wrote: >> >> > 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 >> > >> > >> > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ronan Viernes |
last post by:
Hi,
I have created a python script (see below) to count the maximum number
of threads per process (by starting new threads continuously until it
breaks).
######
#testThread.py
import...
|
by: Al Tobey |
last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and
noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am
building with -Dusethreads. With newer Linux...
|
by: m |
last post by:
Hello,
I have an application that processes thousands of files each day. The
filenames and various related file information is retrieved, related
filenames are associate and placed in a linked...
|
by: Kovan Akrei |
last post by:
Hi,
I would like to know how to reuse an object of a thread (if it is possible)
in Csharp? I have the following program:
using System;
using System.Threading;
using System.Collections;
...
|
by: bygandhi |
last post by:
Hi -
I am writing a service which will check a process and its threads for
their state ( alive or dead ).
The process has 5 .net managed threads created using thread.start and
each have been...
|
by: [Yosi] |
last post by:
I would like to know how threads behavior in .NET .
When an application create 4 threads for example start all of them, the OS
task manager will execute all 4 thread in deterministic order manes,...
|
by: RahimAsif |
last post by:
Hi guys,
I would like some advice on thread programming using C#.
I am writing an application that communicates with a panel over
ethernet, collects data and writes it to a file. The way the...
|
by: mjheitland |
last post by:
Hi,
I like to know how many threads are used by a Threading.Timer object.
When I create a Threading.Timer object calling a short running method
every 5 seconds I expected to have one additional...
|
by: Darian |
last post by:
Is there a way to find all the thread names that are running in a
project?
For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that...
|
by: tdahsu |
last post by:
All,
I'd appreciate any help. I've got a list of files in a directory, and
I'd like to iterate through that list and process each one. Rather
than do that serially, I was thinking I should...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |