110,561
社区成员
发帖
与我相关
我的任务
分享
public static class MessgePool
{
static Queue<string> msgs;
static object syncObj;
static MessgePool()
{
msgs = new Queue<string>();
syncObj = new object();
}
public static void WriteMessage(string msg)
{
lock (syncObj)
{
msgs.Enqueue(msg);
}
}
public static bool ReadMessage(ref string msg)
{
lock (syncObj)
{
if(msgs.Count > 0)
{
msg = msgs.Dequeue();
return true;
}
else
{
return false;
}
}
}
}