|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Wait for all ThreadPool workers to completeI 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. Hello, Michael!
MDO> I have an application that needs to limit the number of simultaneous MDO> threads that are executing at any given time. The threadpool appears MDO> to be ideal for this. However, I need to have my Sub Main wait until MDO> all queued workers are complete. Is there anyway to do this short of MDO> polling 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<AutoResetEvent> events = 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); } 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. Show quote "Vadym Stetsyak" <vady***@ukr.net> wrote in message news:%23qHDmvcwGHA.5044@TK2MSFTNGP05.phx.gbl... > Hello, Michael! > > MDO> I have an application that needs to limit the number of simultaneous > MDO> threads that are executing at any given time. The threadpool appears > MDO> to be ideal for this. However, I need to have my Sub Main wait until > MDO> all queued workers are complete. Is there anyway to do this short of > MDO> polling 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<AutoResetEvent> events = 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 Hello, Michael!
You can limit ThreadPool worker thread count. Or if your server uses sockets you can use async io, like BeginXXX/EndXXX 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/D7E688B8-0BDD-4D44-9A0F-4CD26FB35F51.dcik Show quote "Vadym Stetsyak" <vady***@ukr.net> wrote in message news:OumxwwfwGHA.1624@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 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. Show quote "sloan" <sl***@ipass.net> wrote in message news:%23NiGhohwGHA.5064@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/D7E688B8-0BDD-4D44-9A0F-4CD26FB35F51.dcik > > > "Vadym Stetsyak" <vady***@ukr.net> wrote in message > news:OumxwwfwGHA.1624@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 > > and I thought thread per process was unscalable :D
Show quote "Michael D. Ober" <ober***@.alum.mit.edu.nospam> wrote in message news:uhemfuhwGHA.2400@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.net> wrote in message > news:%23NiGhohwGHA.5064@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/D7E688B8-0BDD-4D44-9A0F-4CD26FB35F51.dcik >> >> >> "Vadym Stetsyak" <vady***@ukr.net> wrote in message >> news:OumxwwfwGHA.1624@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 >> >> > > It appears to scale just fine on VMS.
Mike Ober. Show quote "Greg Young" <druckdruckREMOVEgo***@hotmail.com> wrote in message news:u9nZmklwGHA.3264@TK2MSFTNGP03.phx.gbl... > and I thought thread per process was unscalable :D > > > "Michael D. Ober" <ober***@.alum.mit.edu.nospam> wrote in message > news:uhemfuhwGHA.2400@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.net> wrote in message >> news:%23NiGhohwGHA.5064@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/D7E688B8-0BDD-4D44-9A0F-4CD26FB35F51.dcik >>> >>> >>> "Vadym Stetsyak" <vady***@ukr.net> wrote in message >>> news:OumxwwfwGHA.1624@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 >>> >>> >> >> > > |
|||||||||||||||||||||||