C
ce_clown
Hi NG,
I'm having a little problem that I cannot solve myself due to missing
experience.
Here's the scenario:
a service starts a number of scheduled tasks that are started as a new
thread, each.
One of these tasks has to prepare a number of data records from
different database tables and transfer these into other tables of a
history database. For maximum effectivity the several actions shall be
processed using multithreading. When all steps are finished the task
reports the successful completion to the service.
Using the Thread Pool all steps could be added to the queue using
QueueUserWorkItem and would be processed then. Here, the question is,
how I can make sure that all steps have been finished so that I know
when the task has successfully finished? Apart from that the Thread
Pool examples in the MSDN suggest to use a sleep in order to prevent
the main thread from finishing before the Thread Pool threads even
start working (a join seems to be possible only for individually
started threads) - or are these examples only so much simplified that
methods for waiting for the tasks to finish were just omitted? As a
result I'm just not sure if can I use the Thread Pool in my case.
The alternative - individually started "subthreads" - represents a
less effective (and probably needing more coding efforts) solution
according to the Thread Pool description, but probably it does not
have the problems described above. What I do not know here is how I
can manage hundreds of actions (how many threads? How do I know when
one thread has finished and can start the next action?)
Maybe somebody can give me a hint how I can best solve my problem. By
the way: the app is developped with VS2003/.NET 1.1.
Thanks.
Kind regards
Roland
I'm having a little problem that I cannot solve myself due to missing
experience.
Here's the scenario:
a service starts a number of scheduled tasks that are started as a new
thread, each.
One of these tasks has to prepare a number of data records from
different database tables and transfer these into other tables of a
history database. For maximum effectivity the several actions shall be
processed using multithreading. When all steps are finished the task
reports the successful completion to the service.
Using the Thread Pool all steps could be added to the queue using
QueueUserWorkItem and would be processed then. Here, the question is,
how I can make sure that all steps have been finished so that I know
when the task has successfully finished? Apart from that the Thread
Pool examples in the MSDN suggest to use a sleep in order to prevent
the main thread from finishing before the Thread Pool threads even
start working (a join seems to be possible only for individually
started threads) - or are these examples only so much simplified that
methods for waiting for the tasks to finish were just omitted? As a
result I'm just not sure if can I use the Thread Pool in my case.
The alternative - individually started "subthreads" - represents a
less effective (and probably needing more coding efforts) solution
according to the Thread Pool description, but probably it does not
have the problems described above. What I do not know here is how I
can manage hundreds of actions (how many threads? How do I know when
one thread has finished and can start the next action?)
Maybe somebody can give me a hint how I can best solve my problem. By
the way: the app is developped with VS2003/.NET 1.1.
Thanks.
Kind regards
Roland