线程操作控件

        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)
                {
 if (this.IsHandleCreated)
                    richTextBox1.BeginInvoke(new Action(() =>
                    {
                        richTextBox1.AppendText("11111\r\n");
                    }));
                }
                System.Threading.Thread.Sleep(100);
            }
        }
posted @ 2023-10-15 11:44  冰糖小袁子  阅读(16)  评论(0)    收藏  举报