My, that's a lot of threads...
Regardless, it's pretty unclear what you mean by "do the bookkeeping".
Assuming you mean "how do I keep track of the data coming back from all
those DoTheActualWork () calls, my inclination would be to:
1. create an event in the Process B class which the class can raise to
indicate that a DoTheActualWork () call has finished, and has some results to
share. Create an EventArgs-derived class to hold the actual results you
want to pass back to the rest of the program.
2. Have an event handler in the main part of the program to process all the
events arising from those DoTheActualWork () calls.
If you need to keep track of which particular instance of DoTheActualWork ()
was responsible for a given result, then make sure to give all your threads
unique names when your ProcessA() routine creates them. The individual
this.ProcessB() calls can get their own thread name and include that as part
of their results when they pass results back to the rest of the program via
the EventArgs class. If you're clever about how you name your threads,
you'll be able to determine which thread was which when the results come
back.
If you mean something else by "do the bookkeeping", you'll just have to be
more specific...
"Phillip N Rounds" <pr*****@cassan dragroup.com> wrote in message
news:uJ******** ******@TK2MSFTN GP09.phx.gbl...
I'm cursed by being a linear thinker.
Anyway, I have an application (service) where I can't decide on the
appropriate way to implement threading.
I have a timer which periodically initiates Process A
Process A does something, then has to call N instances of Process B, where
N varies from instance to instance of Process A.
Process B then has to call M(n) instances of Process C, for each n < N,
where again the # of instances of Process C varies for each call to
process B.
Clearly, I can do the following: ( process A & B are really in seperate
worker classes, but this is a simplified version)
Main Class
OnTimer( )
{
int N = CalculateNumber OfProcessARequi rements();
for ( int i = 0; i < N; i++) {
Thread t = new Thread( new ThreadStart( this.ProcessA);
t.Start(); }
return;
}
ProcessA()
{
int M = CalculateNumber OfProcessBRequi rements();
for ( int i = 0; i < M; i++) {
Thread t = new Thread( new ThreadStart( This.ProcessB) }
return;
}
ProcessB()
{
DoTheActualWork ();
return;
}
My question is, how do I do the book-keeping.