palm wrote:
Hi
I have a system.collection.queue object. One thread X enque objects
into this queue and another thread Y dequeues object and process them.
I want to add a listener for this queue in thread Y so that anytime an
object is enqueued into this queue, this method could be invoked. Does
system.collections.queue raises an event anytime a new item is inserted
into it? Any idea and code example will be highly appreciated.
TIA
Hi,
No, it doesn't do anything like that. I guess you have to wrap the
existing queue in a class and add some accessor methods (Queue, Dequeue)
to it. These methods also have to make accessing the underlying queue
thread-safe. You also can't just trigger an event from the *queueing*
thread, as the event handler would run within that thread, which I
suppose is not what you want. This has to be done asynchronously. Or
if it's possible to let the consuming thread wait until the other thread
has placed an object in the queue, you could let the consuming thread
wait on an event, and wake it up after placing the object in the queue.
If that's the case, you might want to look for producer-consumer
problem. It's a classic one.
Cheers,
Benoit