コード例 #1
0
ファイル: FrmMain.cs プロジェクト: Tachiorz/MabiPale2
        /// <summary>
        /// Fired regularly while being connected, handles queued packets.
        /// </summary>
        /// <param name="state"></param>
        private void OnQueueTimer(object state, EventArgs args)
        {
            if (!WinApi.IsWindow(alissaHWnd))
            {
                Disconnect();
            }

            var count = packetQueue.Count;

            if (count == 0)
            {
                return;
            }

            queueTimer.Enabled = false;

            var newPackets = new List <PalePacket>();

            for (int i = 0; i < count; ++i)
            {
                PalePacket palePacket;
                lock (packetQueue)
                    palePacket = packetQueue.Dequeue();

                if (palePacket == null)
                {
                    continue;
                }

                newPackets.Add(palePacket);
            }

            LstPackets.InvokeIfRequired((MethodInvoker) delegate
            {
                LstPackets.BeginUpdate();
                foreach (var palePacket in newPackets)
                {
                    lock (recvFilter)
                        if (Settings.Default.FilterRecvEnabled && recvFilter.Contains(palePacket.Op))
                        {
                            continue;
                        }

                    lock (sendFilter)
                        if (Settings.Default.FilterSendEnabled && sendFilter.Contains(palePacket.Op))
                        {
                            continue;
                        }

                    AddPacketToFormList(palePacket, true);

                    if (palePacket.Received)
                    {
                        pluginManager.OnRecv(palePacket);
                    }
                    else
                    {
                        pluginManager.OnSend(palePacket);
                    }
                }
                LstPackets.EndUpdate();
            });

            UpdateCount();

            queueTimer.Enabled = true;
        }