简体   繁体   中英

Thread Synchronization in C#

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM