//启动线程处理 Thread thread1 = new Thread(UpdateBtn); thread1.IsBackground = true;//设置为后台线程,当主线程结束后,后台线程自动退出,否则不会退出程序不能结束 thread1.Start();
//线程方法,修改Button内容 private void UpdateBtn() int i = 0; while (true) i++; Action action1 = () => button.Content = i; button.Dispatcher.BeginInvoke(action1); // 如果不设置等待,整个程序死循环 Thread.Sleep(500);