message queue

E

Eugene Anthony

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_frames
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:turbo: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
 
G

Guest

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
 

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