Reputation: 665
I have 5 long running process and I need to execute only one Task at a time; I am planning to put them on 5 threads and my only condition is only one thread needs to be exeucuted...
Can you give any example for this ?
Thanks
Upvotes: 0
Views: 169
Reputation: 4375
Do I understand you correctly that you want to execute all 5 threads one after the other. Like: thread 2 shall only start once thread 1 has finished?
Then you can have:
Thread T1 = ...
Thread T2 = ...
Thread T3 = ...
..
Thread T5 = ...
T1.Start();
T1.Join();
T2.Start();
T2.Join();
...
T5.Start();
T5.Join();
But in this case I would advice you to only use 1 thread, that makes things easier.
Upvotes: 0
Reputation: 273179
When you need to execute "one at a time" then do not use more than 1 Thread...
Simply execute them in order on 1 Thread.
Upvotes: 10