线程操作控件

发布时间 2023-10-15 11:48:04作者: 冰糖小袁子
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Thread thread = new System.Threading.Thread(CrossThreadFlush);
            thread.IsBackground = true;
            thread.Start();
        }

        private void CrossThreadFlush()
        {
            while (true)
            {
                if (richTextBox1 != null)
                {
                    richTextBox1.BeginInvoke(new Action(() =>
                    {
                        richTextBox1.AppendText("11111\r\n");
                    }));
                }
                System.Threading.Thread.Sleep(100);
            }
        }