473,471 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Polling on Mutliple MSMQs

Hi All, I have to poll on Multiple Queues for any inbound messages. I was
doing it fine earlier when there was only 1 Queue. I had added the
ReceiveCompletedEventHandler on the Queue and called the BeginReceive
method...
With multiple Queue's its a challenge...
I earlier implemented a logic provided by one of the forum users in which it
said to create an IAsyncResult Handle and then WaitHandle.WaitAny(array)...
but the Problem is when a new message arrives it doesn't notifies me....it
doesn't work the same as the EventHandler...

Here's the snippet I am using for Multiple Queues..its tied inside a WinSvc

protected override void OnStart(string[] args)
{

ThreadPool.QueueUserWorkItem(new WaitCallback(Execute));

}

void Execute(object key)
{

while(true)
{
aresMq1= mq1.BeginReceive();
aresMq2= mq2.BeginReceive();
Process();
}

}

void Process()
{

int iWaitIndex = WaitHandle.WaitAny(new
WaitHandle[]{aresMq1.AsyncWaitHandle, aresMq2.AsyncWaitHandle});

switch (iWaitIndex)
{

case 0:
Message msg1 = mq1.EndReceive(aresMq1);
Stream s1=PrepareMsg(msg1,mq1);
writeMessage(s1,msg1.Label);
break;

case 1:
Message msg2 = mq2.EndReceive(aresMq2);
Stream s2=PrepareMsg(msg2,mq2);
writeMessageEx(s2,msg2.Label);
break;

}
}

Mar 13 '06 #1
1 1442

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
| Hi All, I have to poll on Multiple Queues for any inbound messages. I was
| doing it fine earlier when there was only 1 Queue. I had added the
| ReceiveCompletedEventHandler on the Queue and called the BeginReceive
| method...
| With multiple Queue's its a challenge...
| I earlier implemented a logic provided by one of the forum users in which
it
| said to create an IAsyncResult Handle and then
WaitHandle.WaitAny(array)...
| but the Problem is when a new message arrives it doesn't notifies me....it
| doesn't work the same as the EventHandler...
|
| Here's the snippet I am using for Multiple Queues..its tied inside a
WinSvc
|
| protected override void OnStart(string[] args)
| {
|
| ThreadPool.QueueUserWorkItem(new WaitCallback(Execute));
|
| }
|
| void Execute(object key)
| {
|
| while(true)
| {
| aresMq1= mq1.BeginReceive();
| aresMq2= mq2.BeginReceive();
| Process();
| }
|
| }
|
| void Process()
| {
|
| int iWaitIndex = WaitHandle.WaitAny(new
| WaitHandle[]{aresMq1.AsyncWaitHandle, aresMq2.AsyncWaitHandle});
|
| switch (iWaitIndex)
| {
|
| case 0:
| Message msg1 = mq1.EndReceive(aresMq1);
| Stream s1=PrepareMsg(msg1,mq1);
| writeMessage(s1,msg1.Label);
| break;
|
| case 1:
| Message msg2 = mq2.EndReceive(aresMq2);
| Stream s2=PrepareMsg(msg2,mq2);
| writeMessageEx(s2,msg2.Label);
| break;
|
| }
| }
|
|

Why not simply create a thread per message queue, you don't have hundreds of
queue's I suppose?
Also, don't use the threadpool from OnStart, create a regular thread.

Willy.
Mar 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sporge | last post by:
Hi All Is there any way to decrease the polling interval that Oracle uses to determine if there are jobs pending in the job queue. It appears that it takes up to 5 seconds for a job to be...
0
by: Vijay Varadan | last post by:
We're using Enterprise Application Block June 2005 w/ Visual Studio 2003 .NET. We've configured our ASP.NET web service to run under a specific domain account using the instructions at...
1
by: Daniel Bass | last post by:
hey guys. overview --------- I'm designing a messaging system that works on the principle of late binding to the I/O objects, depending on the .Net class libraries present in the local folder....
2
by: Viet | last post by:
I have a couple of questions that hopefully someone could clarify for me. I have an app that uses the threading.timer to constantly poll a scanner to scan in documents. I understand that Async...
0
by: Viet | last post by:
I understand that Asynchronous delegates can be used to poll but most of the examples show the polling being done for a specified period of time. Are there any examples in VB.NET forms that show...
1
by: engwar | last post by:
Is anyone aware of any freely available software written in a .Net language for adding polling features to an existing website? I'm looking for just a polling component and not interested in...
1
by: kelvin.jones | last post by:
Hi guys, I have read several discussions on this group (and others) that talk about polling a server using ajax transactions and if it is possible to push to the client. The general consensus seems...
5
by: Mike | last post by:
Hi everyone, I would like to be able to send updates to my web page from the server. If I understood correctly, this is not possible to achieve in a web environment, unless some sort of polling...
13
by: LordHog | last post by:
Hello all, I have a little application that needs to poll a device (CAN communications) every 10 to 15 ms otherwise the hardware buffer might overflow when there are message burst on the bus. I...
3
by: Chris Mullins [MVP - C#] | last post by:
I'm sitting on the fence on this one, and wanted to get some other people's input. If you're a big B2B person, I would love to hear your feedback... I've got a SOA system. It's based on a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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
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...

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.