wpf 异步操作

new Thread(() =>
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                   //添加操作
                }));
            }).Start();
public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            for (int i = 0; i < 1000000; i++)
            {
            //text是一个textblock
                text.Text = Convert.ToString(i);
            }
            new Thread(() =>
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                    Thread.Sleep(5000);
                    for (int i = 0; i < 1000000; i++)
                    {
                    //textInDis是一个textblock
                        textInDis.Text = Convert.ToString(i);
                    }
                }));
            }).Start();
        }
    }

你可能感兴趣的:(wpf)