468,457 Members | 1,779 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

queue listener

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

Nov 16 '05 #1
3 3982
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
Nov 16 '05 #2
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.
Benoit Vreuninckx wrote:
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


Nov 16 '05 #3
palm wrote:
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.

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
mailto:la***@vkarlsen.no
PGP KeyID: 0x0270466B
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by phil | last post: by
1 post views Thread by Kishore Gopalan | last post: by
7 posts views Thread by RobKinney1 | last post: by
9 posts views Thread by Paul Rubin | last post: by
8 posts views Thread by Chizl | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.