实时刷新winform中的某一个控件上的文字
2020-12-13 16:50
                         标签:winform   blog   io   ar   sp   for   div   on   art      需要注意的是,必须从UI线程,另外启动一个线程才可以。 在新线程调用异步刷新就OK了   实时刷新winform中的某一个控件上的文字 标签:winform   blog   io   ar   sp   for   div   on   art    原文地址:http://www.cnblogs.com/chucklu/p/4087469.html Thread thread;
        private void button1_Click(object sender, EventArgs e)
        {
            thread = new Thread(new ThreadStart(AnotherRefresh));
            thread.IsBackground = true; 
            thread.Start();
        }
        private void AnotherRefresh()
        {
            MyRefresh("hello world");
            Thread.Sleep(1000);
            MyRefresh("Bye Bye");
        }
        private void MyRefresh(string str)
        {
            try
            {
                this.Invoke((MethodInvoker)delegate()
                {
                    textBox1.Text = str;
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
文章标题:实时刷新winform中的某一个控件上的文字
文章链接:http://soscw.com/index.php/essay/36534.html