日期:2014-05-17  浏览次数:21696 次

C# this.InvokeRequired
哪个大侠能帮我解释下下面代码是什么意思么。这是串口通信的代码,txtReceive是接收的控件名,谢谢了~        
public delegate void UpdateString(object NewData);
        public void UpdateRecevie(object NewData)
        {
            if (this.InvokeRequired)//等待异步
            {
                UpdateString _myInvoke = new UpdateString(UpdateRecevie);
                this.Invoke(_myInvoke, new object[] { NewData });
            }
            else
            {
                txtReceive.AppendText(NewData.ToString());
                txtReceive.SelectionStart = txtReceive.Text.Length - 1;
                txtReceive.ScrollToCaret();
            }
        }
        public void UpdateReceiveCount(object NewCount)
        {
            if (this.InvokeRequired)//等待异步
            {
                UpdateString _myInvoke = new UpdateString(UpdateReceiveCount);
                this.Invoke(_myInvoke, new object[] { NewCount });
            }
            else
            {
                lblRCount.Text = (Convert.ToInt32(lblRCount.Text) + Convert.ToInt32(NewCount)).ToString();
            }
        }