473,408 Members | 2,832 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,408 software developers and data experts.

WaitAll with threadpool

Hello,
here's my problem (I've been searching for a fews days already and couldn't
find a solution)

I've got a bunch of mails to create, so I'd like to queue jobs in a
threadpool (which I can do already), but once all jobs are queued, I'd like
the main thread to wait until all mails are generated.
So far I haven't found how to do that, since the threadpool doesn't provide
an adapted WaitAll method.
Could anyone help please ?
Thanks
Nov 20 '05 #1
10 5562
Cor
Hi Shad
\\\\
Threading.Thread.Sleep(10000) ' 10 seconds
/////
I hope this helps a little bit?
Cor
Nov 20 '05 #2
"Cor" <no*@non.com> wrote in news:3f7a9ba9$0$19776$48b97d01
@reader21.wxs.nl:
Hi Shad
\\\\
Threading.Thread.Sleep(10000) ' 10 seconds
/////
I hope this helps a little bit?
Cor


Hmm nope,
each mail might take up to 10 seconds to generate and i can have up to
1500 of them.
So what I'd really like is a way to know when they're all done
(something else than just counting how many threads I create and then
decrementing each time working thread finishes (I can detect that with
an event)).
I have found on the web a component that implements WaitAll for a
threadpool, but it's in C# and I'd really like toi stick to VB and
understand what I'm doing.

Or is it possible to queue my main thread at the end of the threadpool,
so it takes back control when all others threads are done ?

Thanks for the tip anyway
Nov 20 '05 #3
Cor
Hi Shad,
I did not want add it this time, mostly I set this in a loop as answer
\\\\
do while eventnotbeen
application.doevents
threading.thread.sleep(100)
loop
/////

Cor
Nov 20 '05 #4
"Cor" <no*@non.com> wrote in news:3f7ab0ef$0$32097$48b97d01
@reader21.wxs.nl:
Hi Shad,
I did not want add it this time, mostly I set this in a loop as answer
\\\\
do while eventnotbeen
application.doevents
threading.thread.sleep(100)
loop
/////

Cor


But it's still the same problem, the point is that I don't have only one
working thread, so this cannot be done, unless there is an event raised
when the threadpool completes its last job, is that what you're saying ?
Nov 20 '05 #5
Cor
Shad,
I do it in that way yes, keep track wich threads are active, therefore I
just have a counter
when the counter is zero all threads are done.
Cor
Nov 20 '05 #6
"Cor" <no*@non.com> wrote in news:3f7ab4d5$0$18249$48b97d01
@reader21.wxs.nl:
Shad,
I do it in that way yes, keep track wich threads are active, therefore I
just have a counter
when the counter is zero all threads are done.
Cor


I see.
I was just hoping there'd be a better solution, but I guess that'll have to
do.
Thanks a lot for your help
Nov 20 '05 #7
Shad,
Create a class that represents each request going into the ThreadPool (if
you have not already done so).

One member of this class is a System.Threading.ManualResetEvent object.

Your main thread needs to have an array of the ManualResetEvent objects in
each request. The main thread does a WaitHandle.WaitAll on this array of
ManualResetEvent objects. Remember that ManualResetEvent inherits from
WaitHandle so it has the WaitAll method also.

Each queue job sets its ManualResetEvent when it is finished.

Of course the above means that the main thread will be blocking until all
the queue jobs are done. If the main thread is a UI thread this is NOT
desirable!

Hope this helps
Jay

"Shad" <none> wrote in message news:Xn******************@213.228.0.32...
Hello,
here's my problem (I've been searching for a fews days already and couldn't find a solution)

I've got a bunch of mails to create, so I'd like to queue jobs in a
threadpool (which I can do already), but once all jobs are queued, I'd like the main thread to wait until all mails are generated.
So far I haven't found how to do that, since the threadpool doesn't provide an adapted WaitAll method.
Could anyone help please ?
Thanks

Nov 20 '05 #8
"Cor" <no*@non.com> scripsit:
\\\\
Threading.Thread.Sleep(10000) ' 10 seconds
/////


The number of "\" and "/" should be matching.

SCNR

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
"Cor" <no*@non.com> scripsit:
\\\\
Threading.Thread.Sleep(10000) ' 10 seconds
/////


The number of "\" and "/" should be matching.

SCNR


Aaaaaaahhhhh... ;) I read the statement 10 times and didn't find a division
operator...

--
Armin

Nov 20 '05 #10
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
news:#0**************@TK2MSFTNGP11.phx.gbl:
Shad,
Create a class that represents each request going into the ThreadPool
(if you have not already done so).

One member of this class is a System.Threading.ManualResetEvent
object.

Your main thread needs to have an array of the ManualResetEvent
objects in each request. The main thread does a WaitHandle.WaitAll on
this array of ManualResetEvent objects. Remember that ManualResetEvent
inherits from WaitHandle so it has the WaitAll method also.

Each queue job sets its ManualResetEvent when it is finished.

Of course the above means that the main thread will be blocking until
all the queue jobs are done. If the main thread is a UI thread this is
NOT desirable!

Hope this helps
Jay

"Shad" <none> wrote in message
news:Xn******************@213.228.0.32...
Hello,
here's my problem (I've been searching for a fews days already and

couldn't
find a solution)

I've got a bunch of mails to create, so I'd like to queue jobs in a
threadpool (which I can do already), but once all jobs are queued,
I'd

like
the main thread to wait until all mails are generated.
So far I haven't found how to do that, since the threadpool doesn't

provide
an adapted WaitAll method.
Could anyone help please ?
Thanks



This is more like what i was looking for.
Thanks Jay, I'll try it
Nov 20 '05 #11

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...
5
by: Duane Pressley | last post by:
I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: 1.. A classic ASP page instantiates and calls...
1
by: doudou-shen | last post by:
I will use threadpool do some work with threadpool . but I haven't any information about it . who can help me! thank a lot
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...
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...
1
by: Larry Lard | last post by:
Just now I translated Jon Skeet's WaitHandle.WaitAny / .WaitAll (<http://yoda.arachsys.com/csharp/threads/waithandles.shtml>) from C# into VB.NET, and after the first go I ran into trouble: ...
3
by: Kevin | last post by:
Using this: http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx as an example I have a question concerning the reuse of objects. In the example 10 instances of the Fibonacci class...
5
by: =?Utf-8?B?RkxEYXZlTQ==?= | last post by:
I'm developing an application that gets data from 100 sources (via telnet connections, but you can think stock quotes from a webservice if you like). I was planning on using the thread pool (25...
3
by: UltimateBanoffee | last post by:
Hi, I'm using asp.net 2.0 and I have an understanding issue here! I don't quite understand when the available threads in the ThreadPool are ever used. The application I have running doesn't use...
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: 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:
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...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.