473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

message queue

I am having a problem with my try and catch found in the code bellow. It
never works when there is no msg in the queue. The code bellow is to
read and process one message at a time. Upon completing the process,
only then will the next and so on msg will be processed.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Messaging;
using System.Threading;
using System.Diagnostics;

public partial class _Default : System.Web.UI.Page
{
Thread t;
Process pProcess;
int i = 0;
String path;

protected void Page_Load(object sender, EventArgs e)
{
t = new Thread(new ThreadStart(readQueue));
t.Start();
}

public void readQueue()
{
try
{
MessageQueue queue = new
MessageQueue(".\\Private$\\MyPrivateQueue");
Message msg = queue.Receive(new TimeSpan(0, 0, 5));
msg.Formatter = new
System.Messaging.XmlMessageFormatter(new string[] { "System.String" });
Label1.Text = msg.Body.ToString();
path = msg.Body.ToString();
}
catch (MessageQueueException)
{
Label1.Text = "There is no message in the queue";
}

if(Label1.Text.Length == 0)
{
while (!pProcess.HasExited)
{
if(i==0)
{
pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName =
"C:\\Inetpub\\wwwroot\\mencoder.exe";
pProcess.StartInfo.Arguments = "-lavfopts
i_certify_that_my_video_stream_does_not_use_b_fram es
C:\\Inetpub\\wwwroot\\MAX.mpg -o C:\\Inetpub\\wwwroot\\vuurwerk1.flv -of
lavf -ovc lavc -oac lavc -lavcopts
vcodec=flv:vbitrate=500:autoaspect:mbd=2:mv0:trell :v4mv:cbp:last_pred=3:
predia=2:dia=2:precmp=2:cmp=2:subcmp=2:preme=2:tur bo:acodec=mp3:abitrate
=56 -srate 22050 -af lavcresample=22050";
pProcess.Start();
}

i=i+1;
}
}

i = 0;
Thread.Sleep(5000);
t.Start();
}
}
How do I solve the problem?

Your help is kindly appreciated.
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Feb 17 '07 #1
2 2357
Try this pattern:

catch (MessageQueueException e)
{
// Handle no message arriving in the queue.
if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.IOTimeout)
{
Console.WriteLine("No message arrived in queue.");
// Handle other sources of a MessageQueueException.
// Handle invalid serialization format.
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
// Catch other exceptions as necessary.

return;
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Eugene Anthony" wrote:
I am having a problem with my try and catch found in the code bellow. It
never works when there is no msg in the queue. The code bellow is to
read and process one message at a time. Upon completing the process,
only then will the next and so on msg will be processed.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Messaging;
using System.Threading;
using System.Diagnostics;

public partial class _Default : System.Web.UI.Page
{
Thread t;
Process pProcess;
int i = 0;
String path;

protected void Page_Load(object sender, EventArgs e)
{
t = new Thread(new ThreadStart(readQueue));
t.Start();
}

public void readQueue()
{
try
{
MessageQueue queue = new
MessageQueue(".\\Private$\\MyPrivateQueue");
Message msg = queue.Receive(new TimeSpan(0, 0, 5));
msg.Formatter = new
System.Messaging.XmlMessageFormatter(new string[] { "System.String" });
Label1.Text = msg.Body.ToString();
path = msg.Body.ToString();
}
catch (MessageQueueException)
{
Label1.Text = "There is no message in the queue";
}

if(Label1.Text.Length == 0)
{
while (!pProcess.HasExited)
{
if(i==0)
{
pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName =
"C:\\Inetpub\\wwwroot\\mencoder.exe";
pProcess.StartInfo.Arguments = "-lavfopts
i_certify_that_my_video_stream_does_not_use_b_fram es
C:\\Inetpub\\wwwroot\\MAX.mpg -o C:\\Inetpub\\wwwroot\\vuurwerk1.flv -of
lavf -ovc lavc -oac lavc -lavcopts
vcodec=flv:vbitrate=500:autoaspect:mbd=2:mv0:trell :v4mv:cbp:last_pred=3:
predia=2:dia=2:precmp=2:cmp=2:subcmp=2:preme=2:tur bo:acodec=mp3:abitrate
=56 -srate 22050 -af lavcresample=22050";
pProcess.Start();
}

i=i+1;
}
}

i = 0;
Thread.Sleep(5000);
t.Start();
}
}
How do I solve the problem?

Your help is kindly appreciated.
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Feb 17 '07 #2
still no message displayed.

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Feb 17 '07 #3

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

Similar topics

0
by: Gary | last post by:
I am planning to implement application to application communication using message queueing. I am using VB.NET on a Win2000 server OS with message queueing services enabled. I am find the...
2
by: Rodrigo García | last post by:
Hi. The problem is a bit hard to explain. I have a ServicedComponent method which runs a distributed transaction consisting on a a MessageQueue reception and several database operations. That...
4
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the...
4
by: Tingo | last post by:
Hi all, Is it possible to create a message queue with a specific ID? I want to do this because I'm trying to write a piece of software which restores communicating processes (which communicate...
8
by: Brian Keating EI9FXB | last post by:
Would I be correct in saying that the only way to get a user message into a Windows form would be to use P/Invoke with Message? Of is there some part of the .NET API that I am totally un aware...
6
by: les | last post by:
Here's a class which uses 2.0 generics to implement an inter-thread message queue in C#. Any number of threads can post and read from the queue simultaneously, and the message object can be any...
1
by: Andrew Robert | last post by:
Hi everyone, Could someone help explain what I am doing wrong in this code block? This code block is an excerpt from a larger file that receives transmitted files via IBM WebSphere MQSeries...
1
by: davidcollins001 | last post by:
Hi, I am trying to implement a blocked or synchronous method of message passing using signal interrupts. So far I have the following: server.c { msgget(queue) msgrcv (queue mtype) ...
2
by: bernd | last post by:
Hi netties, posted this in a different group already, which seems to be inappropriate. I create a message queue with msgget(), sent a 5-byte message to it with msgsnd() and try to receive the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.