From 02e94317e4eb165ec02df2c4996ef01a3e5e58af Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Tue, 3 Dec 2024 20:05:12 +0800 Subject: [PATCH] testflag --- .../Assets/Script/Network/NetMsg.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/Network/NetMsg.cs b/AxibugEmuOnline.Client/Assets/Script/Network/NetMsg.cs index cd8cf07..4c38e86 100644 --- a/AxibugEmuOnline.Client/Assets/Script/Network/NetMsg.cs +++ b/AxibugEmuOnline.Client/Assets/Script/Network/NetMsg.cs @@ -17,6 +17,8 @@ namespace AxibugEmuOnline.Client.Network private NetMsg() { } + public static object lockQueueObj = new object(); + #region RegisterMsgEvent public void RegNetMsgEvent(int cmd, Action callback) @@ -61,15 +63,21 @@ namespace AxibugEmuOnline.Client.Network #region PostEvent public void EnqueueNesMsg(int cmd, int ERRCODE, byte[] arg) { - queueNetMsg.Enqueue((cmd, ERRCODE, arg)); + lock (lockQueueObj) + { + queueNetMsg.Enqueue((cmd, ERRCODE, arg)); + } } public void DequeueNesMsg() { - while (queueNetMsg.Count > 0) + lock (lockQueueObj) { - (int, int, byte[]) msgData = queueNetMsg.Dequeue(); - PostNetMsgEvent(msgData.Item1, msgData.Item2, msgData.Item3); + while (queueNetMsg.Count > 0) + { + (int, int, byte[]) msgData = queueNetMsg.Dequeue(); + PostNetMsgEvent(msgData.Item1, msgData.Item2, msgData.Item3); + } } }