线程间操作无效

          第一种方法:  //线程开始的时候加这么一句(把错误隐藏掉)

            Control.CheckForIllegalCrossThreadCalls = false;

 

第二种方法:(建议采用)

//建立个委托
        private delegate void ShowDelegate(string strshow);

 

        public void Show(string strshow)

        {

 

            if (this.txtreceive.InvokeRequired)

            {

             //   this.txtreceive.BeginInvoke(new ShowDelegate(Show), strshow);//这个也可以

                this.txtreceive.Invoke(new ShowDelegate(Show), strshow);

            }

            else

            {

                    this.txtreceive.Text += strshow;

 

            }

        }

posted @ 2014-06-30 13:12  明济安  阅读(136)  评论(0编辑  收藏  举报