首页 > 编程语言 > 详细

C#子线程调用主线程控件

时间:2018-06-08 15:33:36      阅读:442      评论:0      收藏:0      [点我收藏+]

代码如下:

private void ShowMsg(string msg)
        { 
            if (this.InvokeRequired) 
            { 
                this.Invoke(new Action<string>(ShowMsg), msg); 
            } 
            else
            {
                this.txbLog.AppendText(msg);
            } 
        }

private void btnLive_Click(object sender, EventArgs e)
        {
            if (this.btnLive.Text == "Live")
            {
                islive = true;
                this.btnLive.Text = "Manual";
                thread1 = new Thread(Live);
                thread1.Start();
            }
            else
            {
                islive = false;
                this.btnLive.Text = "Live";
                thread1.Abort();
            }
        }

        private void Live()
        {
            while (islive)
            {
                string result="123";
                this.ShowMsg(result);
                Thread.Sleep(500);
            }
        }

 

C#子线程调用主线程控件

原文:https://www.cnblogs.com/kaqiu/p/9155692.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!