Last post Oct 07, 2014 05:17 AM by May Wang
Oct 06, 2014 06:20 AM|Fr3sh|LINK
I'm planning to implement this:
1) the user generates some sort of batch jobs (and sees the list of jobs in the UI)
2) the application processes each job one after another, but 2 jobs simultanously
Until now I'd implement a ConcurrentQueue, and dequeue each job one after another.
But there still is number 3:
3) The user is able to cancel a queued job or a currently running one.
As dequeue simply gets the next item, I am not able to remove an unwanted item that is located somewhere in the middle of the concurrentQueue.
If I don't use concurrentQueue, then I'd also need to implement the removal of completed jobs in a thread safe way,
so Add, Get and Remove would not interfere.
Could anyone please give me a hint on this one?
Oct 07, 2014 05:17 AM|May Wang|LINK
Thanks for posting here.
IProducerConsumerCollection<T> Interface defines methods to manipulate thread-safe collections intended for producer/consumer usage. This interface provides a unified representation for producer/consumer
collections so that higher level abstractions such as System.Collections.Concurrent.BlockingCollection<T> can use the collection
as the underlying storage mechanism.
You may have a try to use System.Collections.Concurrent.BlockingCollection<T>, because there are many removing items methods
for you to handle any item you wanted. Or if you have any special requirements, you can write your own class inherited from interface
System.Collections.Concurrent.BlockingCollection<T> and implement your own removing method through implementing the