How can I continually monitor a group of threads and can take some action after it ends.
My code is as follows:
int threadcount = 5; For (Int i = 0; I In the above case, 5 threads (_azgetThread) have been created and I would like to monitor them and when they will know.
I'm familiar with _azgetThread. I IsAlive but there are many examples in this case.
Using a good option here can each thread complete the event, and the main thread only Check to see if the event is set or call it.
You always have the same mechanism ( IsAlive ), but instead of using one variable for your thread or for all 5 thread instead of list & lt ; Thread & gt; will need to be stored. It is being said, I suggest using TPL instead of individual threads. Depending on your work, you can use parallel.for or parallel.forh to run all 5 objects, or use PLINQ in a collection of items Can also do If you want to keep the same logic, you can use the Task.Factory.StartNew and schedule the task that will notify you at the completion of 5 initial tasks.
No comments:
Post a Comment