c# - Process stack items in several threads -


I have, in addition to each item in which the URL is some web resource, I have N Threads (Actually Tasks ), each of which stops an item from the stack process and adds results (on the result store) based on some criteria in this stack or other output queue. This should be done, until the pile is empty.

What is a great way to recognize the end of this process and stop this work? In other words, how it is recognized that the stack is empty and there is no execution task which will add more items to the stack

The termination condition occurs when all stack reading tasks all are waiting for an item that the heap can be moved. Of course, this can only happen when you provide a way for your work so that you wait for that event. As with the other answers suggested, you can use the intercept collection at the top of the ConcurrentStack class to implement the sync.

In relation to termination, the easiest way is to complete a task (termination work) waiting for that situation, and all other tasks manipulate an integer that represents the number of tasks that are waiting , Increase it before stopping on collection, and subtract it while receiving an item. When that number reaches the total number of possible readership for the stack, then the activity tries to get an item triggers the status variable before it stops, which will wake up the end thread.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -