wPF,解决UI界面实时更新的问题

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(Run));
            thread.IsBackground = true;
            thread.Start();
        }


        public void Run()
        {
            for (int i = 0; i < 1000; i++)
            {
                this.Dispatcher.BeginInvoke((Action)delegate() 
                {
                    string passedSns = i + Environment.NewLine + this.textBox1.Text;
                    this.textBox1.Text = passedSns;
                    textBox1.Foreground = new SolidColorBrush(Colors.Red);
                });
               
                //给界面更新TextBox的时间
                Thread.Sleep(10);
            }
        }
原文地址:https://www.cnblogs.com/simonryan/p/3738188.html