queue listener

P

palm

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
 
B

Benoit Vreuninckx

palm said:
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
 
P

palm

Thanks for your response Benoit.

I was more thinking on these lines of something like overriding some
onInsertComplete for the queue ( by implementing any interface .net
provide??) and raise the event from within this method. Does this sound
like a solution in .Net. Sorry if this is a stupid question but i am
novoice to .net world.
 
?

=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

palm said:
Thanks for your response Benoit.

I was more thinking on these lines of something like overriding some
onInsertComplete for the queue ( by implementing any interface .net
provide??) and raise the event from within this method. Does this sound
<snip>

I got a queue class in my library that is thread-enabled, basically you
can push items into the queue and pop them off. If the queue is empty
when you try to pop off an item, the pop call will block until an item
is pushed into the queue in another thread. You also specify a maximum
size and if the queue ever becomes full, the thread that tries to push
an item into it will also block until the queue gets room for the item.

It also got timeout support so you don't have to wait indefinitely.

http://www.vkarlsen.no/lvk.net

download links up to the right in the little blue box next to the
overview post. Full source so you can just take what you need.

Fairly old release but I haven't fixed any major bugs in a while anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top