473,586 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5574
Cor
Hi Shad
\\\\
Threading.Threa d.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.n l:
Hi Shad
\\\\
Threading.Threa d.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.doe vents
threading.threa d.sleep(100)
loop
/////

Cor
Nov 20 '05 #4
"Cor" <no*@non.com> wrote in news:3f7ab0ef$0 $32097$48b97d01
@reader21.wxs.n l:
Hi Shad,
I did not want add it this time, mostly I set this in a loop as answer
\\\\
do while eventnotbeen
application.doe vents
threading.threa d.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.n l:
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.Threadin g.ManualResetEv ent object.

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

Each queue job sets its ManualResetEven t 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.Threa d.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.Threa d.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

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

Similar topics

5
12312
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...
5
2754
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 MethodA on COM+ Class (C1). 2.. MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class (N1). (Note: N1 has been registered using...
1
1384
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
2506
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.
10
8764
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...
1
3579
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: (from the docs for WaitHandle.WaitAll) >> NotSupportedException The number of objects in waitHandles is greater than the system permits. -or-
3
2295
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 are made and then all put in the threadpool at once, which is well within the limits of the threadpool. However, what happens if you want to do...
5
2558
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 at a time). I know I would start all 100 at once and as threads finish, a new thread would become available and the next one would start. However,...
3
2488
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 ThreadPool.QueueWorkItem, and doesn't create any other Threads. So say I have 100 users access my application at the exact same time and they all...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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
3837
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
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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.