473,385 Members | 1,919 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.

Wait for all ThreadPool workers to complete

I have an application that needs to limit the number of simultaneous threads
that are executing at any given time. The threadpool appears to be ideal
for this. However, I need to have my Sub Main wait until all queued workers
are complete. Is there anyway to do this short of polling a counter?

Thanks,
Mike Ober.
Aug 16 '06 #1
6 2948
Sounds like time to write my own thread/connection pool for the server. The
problem is that too many processor intensive threads on the server and it
bogs down.

Thanks,
Mike.

"Vadym Stetsyak" <va*****@ukr.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hello, Michael!

MDOI have an application that needs to limit the number of simultaneous
MDOthreads that are executing at any given time. The threadpool appears
MDOto be ideal for this. However, I need to have my Sub Main wait until
MDOall queued workers are complete. Is there anyway to do this short of
MDOpolling a counter?

AFAIK there is no built-in mechanism in ThreadPool class.
However, you can introduce an array of events that will be set in the
worker threads, while main thread will wait for them.

pseudo code can look like this

//global events list
List<AutoResetEventevents = new List<AutoResetEvent>();

void ThreadWorker()
{
AutoResetEvent finishEvent = new AutoResetEvent(false);

//do some job here

//notify waiting thread
finishEvent.Set();
}

void ThreadThatIsWaitingForWorkers()
{

AutoResetEvent[] waitEvents = events.ToArray();

//wait for all workers to finish
WaitHandle.WaitAll(waitEvents);

}

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Aug 17 '06 #2
Hello, Michael!

You can limit ThreadPool worker thread count.
Or if your server uses sockets you can use async io, like
BeginXXX/EndXXX

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Aug 17 '06 #3

If youre using 2.0 you can limit the total used threads on the ThreadPool.

1.1... there isn't something built in.

I've scoured the internet looking for something like that.

Maybe look at this:
http://dotnetjunkies.com/Tutorial/D7...26FB35F51.dcik
"Vadym Stetsyak" <va*****@ukr.netwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
Hello, Michael!

You can limit ThreadPool worker thread count.
Or if your server uses sockets you can use async io, like
BeginXXX/EndXXX

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Aug 17 '06 #4
My server is written in VMS Basic, which requires a separate process for
each connection. It's those processes I have to manage from the client
side.

Mike.

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>
If youre using 2.0 you can limit the total used threads on the ThreadPool.

1.1... there isn't something built in.

I've scoured the internet looking for something like that.

Maybe look at this:
http://dotnetjunkies.com/Tutorial/D7...26FB35F51.dcik
"Vadym Stetsyak" <va*****@ukr.netwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
>Hello, Michael!

You can limit ThreadPool worker thread count.
Or if your server uses sockets you can use async io, like
BeginXXX/EndXXX

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com


Aug 17 '06 #5
and I thought thread per process was unscalable :D
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:uh**************@TK2MSFTNGP06.phx.gbl...
My server is written in VMS Basic, which requires a separate process for
each connection. It's those processes I have to manage from the client
side.

Mike.

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>
If youre using 2.0 you can limit the total used threads on the
ThreadPool.

1.1... there isn't something built in.

I've scoured the internet looking for something like that.

Maybe look at this:
http://dotnetjunkies.com/Tutorial/D7...26FB35F51.dcik
"Vadym Stetsyak" <va*****@ukr.netwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
>>Hello, Michael!

You can limit ThreadPool worker thread count.
Or if your server uses sockets you can use async io, like
BeginXXX/EndXXX

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com



Aug 17 '06 #6
It appears to scale just fine on VMS.

Mike Ober.

"Greg Young" <dr*******************@hotmail.comwrote in message
news:u9**************@TK2MSFTNGP03.phx.gbl...
and I thought thread per process was unscalable :D
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:uh**************@TK2MSFTNGP06.phx.gbl...
>My server is written in VMS Basic, which requires a separate process for
each connection. It's those processes I have to manage from the client
side.

Mike.

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>>
If youre using 2.0 you can limit the total used threads on the
ThreadPool.

1.1... there isn't something built in.

I've scoured the internet looking for something like that.

Maybe look at this:
http://dotnetjunkies.com/Tutorial/D7...26FB35F51.dcik
"Vadym Stetsyak" <va*****@ukr.netwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
Hello, Michael!

You can limit ThreadPool worker thread count.
Or if your server uses sockets you can use async io, like
BeginXXX/EndXXX

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com




Aug 18 '06 #7

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

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
3
by: Matt C. | last post by:
This is my first attempt at writing a .NET service, and also my first attempt at using threads. I don't know what I'm doing. Below is some simplified code from my service class (inheriting from...
13
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled...
11
by: Peter Kirk | last post by:
Hi there I am looking at using a thread-pool, for example one written by Jon Skeet (http://www.yoda.arachsys.com/csharp/miscutil/). Can anyone tell me if this pool provides the possibility to...
10
by: Lenn | last post by:
Hello, I have always used a certain design pattern for multithreaded Windows app; Start new worker thread from UI thread, use events to notify UI threads when something happens, update UI...
11
by: ryan | last post by:
Hi, I've omitted a large chunk of the code for clarity but the loop below is how I'm calling a delegate function asynchronously. After I start the each call I'm incrementing a counter and then...
6
by: Ricardo Vazquez | last post by:
Hello everybody, I'm programming a TCP server. During the stress tests I noticed that maybe my socket-receiving thread became deaf after an hour of heavy stress. I think that the reason could...
7
by: Curious | last post by:
On Jun 10, 3:32 am, <s...@dailycoding.comwrote: Thanks! I'll use thread pool.
3
by: keeling | last post by:
Greetings all, It is my understanding that polling is very bad (I could be wrong, this is just my understanding). But I have a problem that I don't know how to solve without polling. I need...
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: 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...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.