說起來其實很簡單,簡單記錄一下:
1、創建線程(也可以用Task)
Thread thread = new Thread(ChartInitail); thread.Start();
2、更新主頁面控件
this.Dispatcher.BeginInvoke(new Action(() => { //默認背景色 SetTemp.Background = new SolidColorBrush(Color.FromRgb(112, 128, 144)); CurTemp.Background = new SolidColorBrush(Color.FromRgb(25, 25, 112)); }
這里有個坑要避免踩到,this.Dispatcher.BeginInvoke里不要放執行很耗時的操作,否則會導致頁面卡住,完全不能做任何操作,因為this代表的是主線程,主線程在執行很耗時的操作,整個頁面必然會卡住動不了。
