Original Post
Hi all, I have been working on the following C# programming issue for over a week now and don't seem to be getting anyway. So was wondering if anyone would be able to help. I have created a struct called Message I then have two queues of typed Message one normal and the other syncronized which will be used to store the Message structures. However, C# doesn't like Queue.Synchronized for my Message queue. However if I use a string queue then it works perfectly. Anybody got any ideas how to synchronize my Message queue. Looking forward to your replies Cheers Steve [Edited by - WadeyBoi on September 23, 2009 10:51:31 AM]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Collections;
namespace ThreadPractice
{
class Control
{
public struct Message
{
public string name;
public string body;
public Message(string messageName,string messageBody)
{
name = messageName;
body = messageBody;
}
};
private Queue<Message> m_ReceivedQueue;
private Queue<Message> m_ReceivedQueueSyncd;
private Message m_textmessage;
//----------------------------------------------------------------------
public Control(UInt16 rtNumber)
{
// Instantiate Message Object and Queue
m_ReceivedQueue = new Queue<Message>();
m_ReceivedQueueSyncd = Queue.Synchronized(m_ReceivedQueue);
Message m_textmessage = new Message();
m_textmessage.name = "test";
}
//----------------------------------------------------------------------
// Get Received Message Queue
//----------------------------------------------------------------------
public Queue GetMessageQueue()
{
lock (this)
{
return m_ReceivedQueueSyncd;
}
}
public Message getTextMessage()
{
return m_textmessage;
}
}
}