码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-06-08 15:51:03      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:color   lse   IV   thread   this   调用   abort   class   event   

代码如下:

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#子线程调用主线程控件

标签:color   lse   IV   thread   this   调用   abort   class   event   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!