Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralDiagnostic.Process Pin
Paul Watson29-Dec-04 21:50
sitebuilderPaul Watson29-Dec-04 21:50 
GeneralRe: Diagnostic.Process Pin
new_phoenix31-Dec-04 5:35
new_phoenix31-Dec-04 5:35 
GeneralRe: Diagnostic.Process Pin
Paul Watson1-Jan-05 10:19
sitebuilderPaul Watson1-Jan-05 10:19 
GeneralGlobal Shortcut Pin
elitecodex29-Dec-04 12:21
elitecodex29-Dec-04 12:21 
GeneralRe: Global Shortcut Pin
Adam Goossens29-Dec-04 14:50
Adam Goossens29-Dec-04 14:50 
GeneralRe: Global Shortcut Pin
elitecodex30-Dec-04 0:24
elitecodex30-Dec-04 0:24 
GeneralCLosing threads Pin
Ista29-Dec-04 11:56
Ista29-Dec-04 11:56 
GeneralRe: CLosing threads Pin
Adam Goossens29-Dec-04 14:35
Adam Goossens29-Dec-04 14:35 
I'm definitely no expert, but here's my idea:

Class A should expose a ManualResetEvent via a public property. When the class is constructed, create an instance of the ManualResetEvent class and set it's initial state to non-signalled (by passing in false as a parameter to the constructor).

Now every object you create of class A has it's own ManualResetEvent, which can be used to signal when that class has completed it's work by calling ManualResetEvent.Set().

When you create an object of class A, store it's ManualResetEvent in an array of type WaitHandle. This could be the tricky part - if you create the object before the thread starts, you should have no problems. However, if the thread creates the object, this method will not work (as you can't get a hold of the object).

The controller will then create all of your threads and keep them in a collection for access later so that you can call Join on them.

Now, perform any processing you need to do for the Controller and when you're ready to wait for your signal from one of the classes, simply call WaitHandle.WaitAny(WaitHandle[]), and pass in your collection of WaitHandles as the parameter.

WaitHandle.WaitAny() will immediately return when any of the WaitHandles becomes signalled. Once this occurs, loop through your collection of threads and call Thread.Join() on each of them.

I hope that makes sense. It may not be the best way to do it, but that's what I would do personally (like I said, I'm not expert Wink | ;) ).

This space for rent!
My Blog
GeneralRe: CLosing threads Pin
Ista30-Dec-04 4:53
Ista30-Dec-04 4:53 
GeneralRe: CLosing threads Pin
Adam Goossens30-Dec-04 13:03
Adam Goossens30-Dec-04 13:03 
GeneralThread and Not Responding Pin
brunoconde29-Dec-04 9:48
brunoconde29-Dec-04 9:48 
GeneralRe: Thread and Not Responding Pin
Tom Larsen29-Dec-04 10:49
Tom Larsen29-Dec-04 10:49 
GeneralRe: Thread and Not Responding Pin
Heath Stewart29-Dec-04 11:23
protectorHeath Stewart29-Dec-04 11:23 
GeneralRe: Thread and Not Responding Pin
Tom Larsen30-Dec-04 4:29
Tom Larsen30-Dec-04 4:29 
GeneralRe: Thread and Not Responding Pin
Heath Stewart30-Dec-04 5:17
protectorHeath Stewart30-Dec-04 5:17 
GeneralRe: Thread and Not Responding Pin
Heath Stewart29-Dec-04 11:06
protectorHeath Stewart29-Dec-04 11:06 
GeneralRe: Thread and Not Responding Pin
PaleyX1-Apr-05 2:50
PaleyX1-Apr-05 2:50 
GeneralRe: Thread and Not Responding Pin
Heath Stewart1-Apr-05 7:03
protectorHeath Stewart1-Apr-05 7:03 
GeneralRe: Thread and Not Responding Pin
PaleyX1-Apr-05 7:17
PaleyX1-Apr-05 7:17 
GeneralRe: Thread and Not Responding Pin
Heath Stewart2-Apr-05 1:25
protectorHeath Stewart2-Apr-05 1:25 
GeneralRe: Thread and Not Responding Pin
PaleyX2-Apr-05 1:53
PaleyX2-Apr-05 1:53 
GeneralRe: Thread and Not Responding Pin
Heath Stewart3-Apr-05 6:41
protectorHeath Stewart3-Apr-05 6:41 
GeneralRe: Thread and Not Responding Pin
PaleyX4-Apr-05 5:37
PaleyX4-Apr-05 5:37 
GeneralRe: Thread and Not Responding Pin
Heath Stewart4-Apr-05 8:23
protectorHeath Stewart4-Apr-05 8:23 
GeneralRe: Thread and Not Responding Pin
Ashar Khaliq29-Dec-04 11:17
Ashar Khaliq29-Dec-04 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.