473,545 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2975
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.ne twrote in message
news:%2******** ********@TK2MSF TNGP05.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<AutoResetE ventevents = new List<AutoResetE vent>();

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

//do some job here

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

void ThreadThatIsWai tingForWorkers( )
{

AutoResetEvent[] waitEvents = events.ToArray( );

//wait for all workers to finish
WaitHandle.Wait All(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.ne twrote in message
news:Ou******** ******@TK2MSFTN GP02.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.ne twrote in message
news:%2******** ********@TK2MSF TNGP06.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.ne twrote in message
news:Ou******** ******@TK2MSFTN GP02.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.nospamw rote in message
news:uh******** ******@TK2MSFTN GP06.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.ne twrote in message
news:%2******** ********@TK2MSF TNGP06.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.ne twrote in message
news:Ou******* *******@TK2MSFT NGP02.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******** ******@TK2MSFTN GP03.phx.gbl...
and I thought thread per process was unscalable :D
"Michael D. Ober" <obermd.@.alum. mit.edu.nospamw rote in message
news:uh******** ******@TK2MSFTN GP06.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.ne twrote in message
news:%2******* *********@TK2MS FTNGP06.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.ne twrote in message
news:Ou****** ********@TK2MSF TNGP02.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
12308
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 threads from the ThreadPool. However, eventually (relatively quickly) there become fewer and fewer available worker threads in the pool, until there...
3
11648
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 ServiceBase). The OnStart calls a loop, which continues forever on its own thread as long as _keepProcessing is true. This seems to work and I'm...
13
2500
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 'ThreadPool Class ') .... however I would like to ensure that all my ThreadPool threads have completed before I exit my Main function.
11
20327
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 wait for all its threads to finish? For example, if I start 20 threads: CustomThreadPool pool = new CustomThreadPool("PetersThreadPool");...
10
8755
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 controls using delegates through .BeginInvoke. I came across some code samples recently where ThreadPool class is used to start new threads. My...
11
6931
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 making the main thread sleep until the counter gets back to zero. The call back function for each call decrements the counter. Is there a better way to...
6
1621
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 be this: The processing of the received messages. Something goes wrong in this processing and the code gets stuck here. As the processing is within...
7
1622
by: Curious | last post by:
On Jun 10, 3:32 am, <s...@dailycoding.comwrote: Thanks! I'll use thread pool.
3
2870
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 to execute a series of mathematically intensive methods and wait for them ALL to finish before moving on to the next step. I have a machine with lots...
0
7499
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.