private void RecvDataEvent(object sender, RecvEventArgs e)
 {
     ShowPid(textBoxPid, e.SPid);
     ShowPid(textBoxTid, e.STid);
 }
 private void RecvDataEvent(object sender, RecvEventArgs e)
 {
     // textBoxPid.Text = e.SPid;//�̼߳������Ч: �Ӳ��Ǵ����ؼ���textBoxPid�����̷߳�������
     ShowPid(textBoxPid, e.SPid);
     ShowPid(textBoxTid, e.STid);
 }
        public void ReceiveMessages()
        {
            // Receive a message and write it to the console.
            IPEndPoint e = new IPEndPoint(IPAddress.Any, 6035);
            UdpClient u = null;
            UdpState s = null;
            while (true && bIsReceiving)
            {
                try
                {
                    u = new UdpClient(e);
                    s = new UdpState();
                    s.e = e;
                    s.u = u;
                    _AddLog(textBoxLog, "UDP创建OK!");
                    break;
                }
                catch (Exception)
                {
                    _AddLog(textBoxLog, "UDP创建中...");
                    Thread.Sleep(3000);
                }
            }
            while (bIsReceiving)
            {
                Console.WriteLine("listening for messages");
                messageReceived = false;
                u.BeginReceive(new AsyncCallback(ReceiveCallback), s);

                // Do some work while we wait for a message. For this example,
                // we'll just sleep
                while (!messageReceived && bIsReceiving)
                {
                    Thread.Sleep(100);
                }
                if (messageReceived)
                {
                    _AddLog(textBoxLog, receiveString);
                    int nIndex = receiveString.IndexOf(',');
                    string sEpc = "";
                    string sTid = "";
                    if (nIndex != -1)
                    {
                        sEpc = receiveString.Substring(0, nIndex);
                        sTid = receiveString.Substring(nIndex + 1);
                    }
                    else
                    {
                        sEpc = receiveString;
                    }

                    if (sEpc.Length == 24)
                    {
                        sEpc = sEpc.Substring(12, 12);
                    }

                    if (recvEvent != null)
                    {
                        // 得到按键信息的参数
                        RecvEventArgs args = new RecvEventArgs(sEpc, sTid);
                        // 触发事件
                        recvEvent(this, args);
                    }
                }
            }
            s.u.Close();
        }