This commit is contained in:
sin365 2024-12-03 20:05:12 +08:00
parent c0cd7623df
commit f49a7e87d1

View File

@ -17,6 +17,8 @@ namespace AxibugEmuOnline.Client.Network
private NetMsg() { } private NetMsg() { }
public static object lockQueueObj = new object();
#region RegisterMsgEvent #region RegisterMsgEvent
public void RegNetMsgEvent(int cmd, Action<byte[]> callback) public void RegNetMsgEvent(int cmd, Action<byte[]> callback)
@ -61,15 +63,21 @@ namespace AxibugEmuOnline.Client.Network
#region PostEvent #region PostEvent
public void EnqueueNesMsg(int cmd, int ERRCODE, byte[] arg) public void EnqueueNesMsg(int cmd, int ERRCODE, byte[] arg)
{ {
queueNetMsg.Enqueue((cmd, ERRCODE, arg)); lock (lockQueueObj)
{
queueNetMsg.Enqueue((cmd, ERRCODE, arg));
}
} }
public void DequeueNesMsg() public void DequeueNesMsg()
{ {
while (queueNetMsg.Count > 0) lock (lockQueueObj)
{ {
(int, int, byte[]) msgData = queueNetMsg.Dequeue(); while (queueNetMsg.Count > 0)
PostNetMsgEvent(msgData.Item1, msgData.Item2, msgData.Item3); {
(int, int, byte[]) msgData = queueNetMsg.Dequeue();
PostNetMsgEvent(msgData.Item1, msgData.Item2, msgData.Item3);
}
} }
} }