How to ensure that all Threads Report back their status [CS/C# 2005]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
I have a form (frmMain) that spawns a thread (thRemote) that deals with all networking - it in turn spawns a certain number of threads, tcp listeners (thTcpListener) one for each client...
From a Server-side point of view:: Now, when everyone (clients) is ready to proceed (at a certain point) the Server sends a "Start" message to all clients and now must wait for all clients to respond with a "Ready" message before the main thread (thRemote) sends a "GO" message to all clients and then continues (launches).

Specifically, when the tcp listener threads (thTcpListener) recieve a "Ready" message from the client it needs to 'somehow' tell 'thRemote' that this client has responded and is ready.
And somewhere in 'thRemote' I need to be able to check to see everytime I get a "ready" from one of my tcp listener threads if that was the last one I needed and now to continue (send the "GO" message, etc...)

Thing is - I am unsure how to accomplish this task properly - I imagine I could use a DELEGATE function off thRemote that I fire from within my tcp listener threads that increases a counter until I reach my target... Or maybe using EVENTS? or Polling the threads? I am really unsure as to the best course of action...
Any ideas, hints, and help would be greatly appreciated, thanks
 
I would not have a TcpListener instance in each separate thread. I would have a single TcpListener instance in the main thread that waits for incoming client connections. When a connection request is received you pass the new Socket off to a class to handle the communication with the remote client. You can then track each time a new connection is created and, when your overall "ready state" is reached, begin doing whatever it is that you need to do.
 
Back
Top