473,508 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Queue and Thread

First I leave the server running. Then I open up the client and click
the button to send a message to the queue. So when I check the queue its
empty. Possible because all the message in the queue has been read and
deleted. But I am interested to have my code reading one message from
the queue for every 'n' seconds. How is it done?.

Client.aspx.cs
-------------
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;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
MessageQueue queue = new
MessageQueue(".\\Private$\\MyPrivateQueue");
queue.Send("Hello world");
}
}
Server.aspx.cs
--------------

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;

public partial class _Default : System.Web.UI.Page
{
Thread t;

protected void Page_Load(object sender, EventArgs e)
{
t = new Thread(new ThreadStart(readQueue));
t.Start();
}
protected void Button1_Click(object sender, EventArgs e)
{
MessageQueue queue = new
MessageQueue(".\\Private$\\MyPrivateQueue");
queue.Send("Hello world");
}

public void readQueue()
{
Thread.Sleep(10000);

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();
}
catch (MessageQueueException)
{
Label1.Text = "There is no message in the queue";
}

readQueue();
}

protected void Button2_Click(object sender, EventArgs e)
{
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();
}
catch (MessageQueueException)
{
Label1.Text = "There is no message in the queue";
}
}
}

Eugene Anthony

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

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

Similar topics

9
2757
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,...
4
2760
by: Sachin Jagtap | last post by:
Hi, I am getting exception while poping item from queue, I am writing messages coming from client in a queue in one thread and then in other thread i am reading from queue and writing in file....
2
2706
by: Hollywood | last post by:
I have a system in which I have a single thread that places data on a Queue. Then I have one worker thread that waits until data is put on the thread and dequeues the Queue and processes that...
3
4498
by: palm | last post by:
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...
6
4961
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...
0
1610
by: Dave Coate | last post by:
I am working on a generic way to launch multiple similar processes (threads) at once, but limit the number of threads running at any one time to a number I set. As I understand it the following...
6
16690
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...
12
1390
by: Paul Rubin | last post by:
I'd like to suggest adding a new operation Queue.finish() This puts a special sentinel object on the queue. The sentinel travels through the queue like any other object, however, when...
1
2537
by: psaffrey | last post by:
I'm trying to implement an application that will listen for requests, run them when they are present but also be able to add new requests even while it's running. I've tried to do this using the...
19
3363
by: =?ISO-8859-1?Q?Nordl=F6w?= | last post by:
I am currently designing a synchronized queue used to communicate between threads. Is the code given below a good solution? Am I using mutex lock/unlock more than needed? Are there any resources...
0
7231
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
7133
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
7336
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,...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
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,...
0
3214
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
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.