Hi,
I am trying to run a program on message queuing in which the user inserts some info in text boxes from the client side which gets entered into a message queue and the server receives the info by message queue, writes to a file and then reads the file. These are the requirements of my program. Now the client side works ok. But the server displays the info from the client only once with the codes I have written. It doesnt display the info if I insert new info from the client side. What could be the problem?
Below I give WaitForData() function codes which I call inside the function where the client connects to server:
public void WaitForData()
{ System.Messaging.MessageQueue mq;
try
{
if (MessageQueue.Exists(@".\Private$\MyQueueParts"))
//creates an instance MessageQueue, which points to the already existing MyQueueParts
mq = new System.Messaging.MessageQueue(@".\Private$\MyQueueParts");
else
//creates a new private queue called MyQueueParts
mq = MessageQueue.Create(@".\Private$\MyQueueParts");
mq.Formatter = new System.Messaging.XmlMessageFormatter (new Type[] {typeof (WritePartsItems)}) ;
System.Messaging.Message msg = mq.Receive();
WritePartsItems outpartsItems = (WritePartsItems)msg.Body;
using( StreamWriter sw = new StreamWriter(outpartsItems.FileName,true))
{
sw.WriteLine(outpartsItems.Message);
sw.Flush();
}
using (StreamReader sr = new StreamReader(outpartsItems.FileName, true))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Client_Parts_Records.Items.Add(line);
}
}
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
}
}
Any quick help will be much appreciated.
Thanks
I am trying to run a program on message queuing in which the user inserts some info in text boxes from the client side which gets entered into a message queue and the server receives the info by message queue, writes to a file and then reads the file. These are the requirements of my program. Now the client side works ok. But the server displays the info from the client only once with the codes I have written. It doesnt display the info if I insert new info from the client side. What could be the problem?
Below I give WaitForData() function codes which I call inside the function where the client connects to server:
public void WaitForData()
{ System.Messaging.MessageQueue mq;
try
{
if (MessageQueue.Exists(@".\Private$\MyQueueParts"))
//creates an instance MessageQueue, which points to the already existing MyQueueParts
mq = new System.Messaging.MessageQueue(@".\Private$\MyQueueParts");
else
//creates a new private queue called MyQueueParts
mq = MessageQueue.Create(@".\Private$\MyQueueParts");
mq.Formatter = new System.Messaging.XmlMessageFormatter (new Type[] {typeof (WritePartsItems)}) ;
System.Messaging.Message msg = mq.Receive();
WritePartsItems outpartsItems = (WritePartsItems)msg.Body;
using( StreamWriter sw = new StreamWriter(outpartsItems.FileName,true))
{
sw.WriteLine(outpartsItems.Message);
sw.Flush();
}
using (StreamReader sr = new StreamReader(outpartsItems.FileName, true))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Client_Parts_Records.Items.Add(line);
}
}
}
catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
}
}
Any quick help will be much appreciated.
Thanks