欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

多线程操作控件属性和方法

程序员文章站 2022-06-10 10:59:41
...

设置属性和方法

private void button2_Click(object sender, EventArgs e)
        {
            timer.Stop();
            Thread thread = new Thread(() =>
            {
                //this.label1.Text = i.ToString();
                if (this.button1.InvokeRequired)
                {
                    this.button1.Invoke(new Action(() => this.button1.Enabled = true));
                }
                Thread.Sleep(300);
            });
            thread.IsBackground = true;
            thread.Start();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(() =>
            {
                if (this.richTextBox1.InvokeRequired)
                {
                    this.richTextBox1.Invoke(new Action(() => this.richTextBox1.Clear()));
                }
                Thread.Sleep(300);
            });
            thread.IsBackground = true;
            thread.Start();
        }