473,499 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4497
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2756
by: phil | last post by:
And sorry I got ticked, frustrating week >And I could help more, being fairly experienced with >threading issues and race conditions and such, but >as I tried to indicate in the first place,...
1
3720
by: Cherrish Vaidiyan | last post by:
sir, I have a small error in Listener configuration.I have two system with a database in each. I am using Red Hat 9 and Oracle 9i. so i shall anme the database and system. system 1 - node2 ...
3
694
by: Bill | last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...). Why doesn't this work, and is there a work...
1
8645
by: Kishore Gopalan | last post by:
Hi, I have a strange trouble. My application sends messages to a local MSMQ Queue (say 'A') and I use a listener (a windows service) to move the messages to another local queue (say 'B') and my...
6
4957
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
7
1644
by: RobKinney1 | last post by:
Here is another question we have been meaning to post for a long time. My colleague is literally pulling chunks of hair out of his head right now. We have a logging class. This class is...
9
1740
by: Paul Rubin | last post by:
Does anyone have an implementation of a distributed queue? I.e. I have a long running computation f(x) and I'd like to be able to evaluate it (for different values of x) on a bunch of different...
5
38816
by: mivey4 | last post by:
Hi, First off, I am aware that this is a very heavily documented error and I have done my homework for throughly researching probable causes before deciding to post my problem here. At this point,...
8
8897
by: Chizl | last post by:
I'm building a web server and having some issues with the TCPListener.Start(BackLog). It doesn't seem to do as expected. I'm using MS Web Stress Tool to test against my web server and when I...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.