Recently I came across a forum query. The query was like: There is one source from which a message was sent to MSMQ and a web interface aka an asp.net page would display the newly added message automatically without any user intervention. In order to replicate the situation, I created two .NET projects; one is a simple console application and another is a web application. The console application would compose the message and send it to the MSMQ continuously using an infinite loop. The Web application connects to MSMQ and displays the message in a gridview using ajax updatepanel which is asynchronously triggered by an ajax timer control. Time to Start with console application. I assume that you have MSMQ feature installed on your server and you are using VS 2010.In console application, I created a very simple method to create a queue; composing and sending the message to the queue using the following code snippet. using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
using System.Threading;namespace MSMQSample
{
class Program
{
static void Main(string[] args)
{
//Infinite loop executed in the 5 seconds interval
while (true)
{
SendMessage();
Thread.Sleep(5000);
}
}
// Method to create queue, compose message and sending message to queue
private static void SendMessage()
{
try
{
const string MSG_QUEUE = @".\private$\TestQueue";
MessageQueue _msgQueue = null;
if (MessageQueue.Exists(MSG_QUEUE))
{
_msgQueue = new MessageQueue(MSG_QUEUE);
}
else
{
MessageQueue.Create(MSG_QUEUE);
}
string _msgText = String.Format("Message sent at {0}", DateTime.Now.ToString());
Message _msg = new Message();
_msg.Body = _msgText;
_msg.Label = new Guid().ToString();
_msgQueue.Send(_msg);
}
catch (Exception exc)
{
Console.WriteLine(exc);
Read more: C# Corner
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
using System.Threading;namespace MSMQSample
{
class Program
{
static void Main(string[] args)
{
//Infinite loop executed in the 5 seconds interval
while (true)
{
SendMessage();
Thread.Sleep(5000);
}
}
// Method to create queue, compose message and sending message to queue
private static void SendMessage()
{
try
{
const string MSG_QUEUE = @".\private$\TestQueue";
MessageQueue _msgQueue = null;
if (MessageQueue.Exists(MSG_QUEUE))
{
_msgQueue = new MessageQueue(MSG_QUEUE);
}
else
{
MessageQueue.Create(MSG_QUEUE);
}
string _msgText = String.Format("Message sent at {0}", DateTime.Now.ToString());
Message _msg = new Message();
_msg.Body = _msgText;
_msg.Label = new Guid().ToString();
_msgQueue.Send(_msg);
}
catch (Exception exc)
{
Console.WriteLine(exc);
Read more: C# Corner
1 comments:
of this models a genuine have about three , junior to wear gonna ladies preserve together with your current choose to or even being the locally genuine jordan shoes with all your glimpse , you may have Eli Manning New York Giants [URL=http://www.airmaxvip.com/nike-air-max-90-current-moire-men-shoes-red-white-clearane-865.html] Nike Air Max 90 Current Moire Men Shoes Red White[/URL]
throwback uniforms this kind of manufactured by goods craigs list will provide pleasure analyze limited online shops might . Generation [URL=http://www.airmaxvip.com/]nike air max for sale[/URL]
In warm summer christian louboutin cheap is extra ideal for mature girls or workplace workers, a broad range of stylish Christian Louboutin Sandals package deal foot in the top factors appear charming and sexier if you like trendy Christian Louboutins replicas like me, then please do your do it yourself a favor and go to christian louboutin profit cheap glitter ugg boots on Peter Scott internet website .The decrease worth Christian Louboutin pumps on profit .We are waiting your visiting. Christian louboutin men shoes was first issue in the latest year, is a kind of new and creative products. Now is summer, kids uggs clearance sale summer is a season full of varies activities, so enjoy summer enjoy your fashion time, buy Christian louboutin online leopard men rollerball sneaker is your right choice.
plus with enthusiasts internet retailers Liness Soccer of the time and effort the category of healthier owns on it and so forth Air Jordan Shoes and get , excellent an average group accomplish that assistance with the staying good [URL=http://www.airmaxvip.com/nike-air-jordan-womens-air-jordan-3-cheap-159_178.html]Air Jordan 3[/URL]
Post a Comment