473,387 Members | 1,456 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,387 software developers and data experts.

How to know when a thread in a thread pool has finished executing my workitem ?

hi
I'm using QueueUserWorkItem to execute a bunch of tasks using the thread
pool. Once started, I would like to wait for all of them to finish, using
something like WaitAll. Is there a way I can know when a thread pool
workItem has finished executing ? (My only solution at this time is to use
an autoreset event that is reset before I enqueue the workItem, that is set
by my workitem when it finishes.). Is there a built-in mechanism in the
thread pool to avoid using my own autoresetEvent ?
thanks
Nov 16 '05 #1
2 6268
palaga,

Unfortunately, no, there is not. However, it would be rather simple to
write a little wrapper delegate that will do this (instead of injecting it
into your code in every delegate).

The one thing that you have to worry about is handle management. If you
have a large number of items in the thread pool, then you can easily create
too many events which can have an impact on performance.

Check out the .NET Matters section of the October 2004 issue of MSDN
magazine, specifically, the first question. It addresses your exact
problem, as well as provides a good solution. You can find it at (watch for
line wrap):

http://msdn.microsoft.com/msdnmag/is...10/NetMatters/

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"palaga" <fb*********@ubisoft.fr> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
hi
I'm using QueueUserWorkItem to execute a bunch of tasks using the thread
pool. Once started, I would like to wait for all of them to finish, using
something like WaitAll. Is there a way I can know when a thread pool
workItem has finished executing ? (My only solution at this time is to use
an autoreset event that is reset before I enqueue the workItem, that is
set
by my workitem when it finishes.). Is there a built-in mechanism in the
thread pool to avoid using my own autoresetEvent ?
thanks

Nov 16 '05 #2
thanks, the ThreadPoolWait class seems to exactly match my needs !

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news:eB**************@TK2MSFTNGP14.phx.gbl...
palaga,

Unfortunately, no, there is not. However, it would be rather simple to write a little wrapper delegate that will do this (instead of injecting it
into your code in every delegate).

The one thing that you have to worry about is handle management. If you have a large number of items in the thread pool, then you can easily create too many events which can have an impact on performance.

Check out the .NET Matters section of the October 2004 issue of MSDN
magazine, specifically, the first question. It addresses your exact
problem, as well as provides a good solution. You can find it at (watch for line wrap):

http://msdn.microsoft.com/msdnmag/is...10/NetMatters/

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"palaga" <fb*********@ubisoft.fr> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
hi
I'm using QueueUserWorkItem to execute a bunch of tasks using the thread
pool. Once started, I would like to wait for all of them to finish, using something like WaitAll. Is there a way I can know when a thread pool
workItem has finished executing ? (My only solution at this time is to use an autoreset event that is reset before I enqueue the workItem, that is
set
by my workitem when it finishes.). Is there a built-in mechanism in the
thread pool to avoid using my own autoresetEvent ?
thanks


Nov 16 '05 #3

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

Similar topics

4
by: Matt Billock | last post by:
Hello everyone, I am having some issues with what should be an insanely simple problem. Basically, I'm working on an implementation of the TSP algorithm (I have a static set of 5 locations, so...
7
by: VMI | last post by:
In the following code, how can I display the MessageBox once MyThread has finished executing? updateFiles method copies 5 humongous files to the HDD but for some reason, the MessageBox is displayed...
2
by: Ricardo Luceac | last post by:
HI... I have a queue of objects waiting to be analysed by a method, so I think o using threads to analyse 3 objects at the same time... The problem is: I create the 3 threads, and execute...
0
by: Santa | last post by:
I am using Fritz Onion's "Asynchronous Pages" approach as mentioned in the article http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx to increase the performance of my ASPX...
5
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
1
by: Chrace | last post by:
Hi all, I have a problem with with Thread.Join( Timeout ) where the timeout never occurs. I basically need to make a connection to an AS400 box which works fine. Once in a blue moon the AS400...
12
by: Ronny | last post by:
Thanks Chris, Looks nice but I miss the dual way communication. In the main thread to deliver paramters and data to the worker thread- how can I do that? Regards Ronny Take a look at the...
2
by: ssouhrada | last post by:
I have some code below which Queues up Worker Items... The only thing it doesn't do is wait for the application to finish executing it. Any ideas on how I can get the application wait for all these...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...

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.