0

I would like an event to be triggered when an item is added or removed from a Queue.

For example:

  1. A build gets added to a build queue, when it is added I would like a build of the project to occur. Build code locked (thread safe).

  2. A build gets removed from a build queue when it is built. Build code unlocked (thread safe).

Additionally:

I found this previous thread from 2009, I am wondering if there is a newer / better way of going about this.

C#: Triggering an Event when an object is added to a Queue

Thanks.

Community
  • 1
  • 1
mitchellt
  • 954
  • 4
  • 13
  • 26

1 Answers1

1

You can use an ObservableCollection<T>, that already has the events you need. You will need to handle syncronisation yourself then.

OR

You can use ConcurrentQueue<T>, but then you will need to handle the events yourself.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • So I've been looking at ObservableCollection and it has 'OnCollectionChanged'. This goes for add, remove etc but how do I distinguish between add and remove if the same event is being fired for both? It would be nice if you could do something when item is added and something different for an item being removed. Thanks. – mitchellt Dec 30 '13 at 13:41
  • 1
    @mitchellt The event args of that event contain all neccessary information. – nvoigt Dec 30 '13 at 15:05