private QueueMessageBoxNotification()
 {
     ActionMessageBox = (sender, page, title, content, mode, imageMode, buttonMode, command, args) =>
     {
         MsgList.Enqueue(new MessageBoxInfo()
         {
             Sender = sender, Page = page, Title = title, Content = content, Mode = mode, ImageMode = imageMode, ButtonMode = buttonMode, Command = command, Args = args
         });
         MoveNext();
     };
 }
Beispiel #2
0
        public void ReceiveAsync(Message msg)
        {
            if (msg == null)
            {
                return;
            }

            lock (MsgList.SyncRoot)
            {
                MsgList.Enqueue(msg);

                if (Handling)
                {
                    return;
                }

                Handling = true;
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback(MsgHandle), this);
        }
Beispiel #3
0
    /// <summary>
    /// 处理一次接受的数据,期间要对数据的完整性进行判断
    /// </summary>
    public void ProcessData()
    {
        // 如果输入的数据的长度小于4,
        // 那么说明此消息还不足以构成一个数据包
        if (bufferCount < 4)
        {
            return;
        }

        // 获得此消息前4个字节,以此获得数据包长度
        byte[] lenBytes = new byte[4];
        for (int i = 0; i < 4; i++)
        {
            lenBytes[i] = readBuff[i];
        }
        length = ByteArrayToInt(lenBytes);

        // 还未读到完整数据包
        if (bufferCount < length + 4)
        {
            return;
        }

        // 处理消息
        ProtocolBytes protocolBytes = ProtocolBytes.Decode(readBuff, sizeof(Int32), length);

        MsgList.Enqueue(protocolBytes);


        // 清除已处理的消息
        int count = bufferCount - length - 4;

        Array.Copy(readBuff, 4 + length, readBuff, 0, count);
        bufferCount = count;

        if (bufferCount > 0)
        {
            ProcessData();
        }
    }