473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

threads

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
Nov 16 '05 #1
9 2329
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

Nov 16 '05 #2
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

Nov 16 '05 #3
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
Nov 16 '05 #4

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

Nov 16 '05 #5
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




Nov 16 '05 #6
Hmm... I see no code in the attachment.
Nov 16 '05 #7
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.


Nov 16 '05 #8
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
>
>
>

Nov 16 '05 #9
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
>> >
>> >
>> >


Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
0
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...
6
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...
34
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; ...
3
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...
10
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,...
6
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...
3
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...
10
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...
4
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...
1
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...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.