zoukankan      html  css  js  c++  java
  • wpf异步线程更新页面控件

    说起来其实很简单,简单记录一下:

    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代表的是主线程,主线程在执行很耗时的操作,整个页面必然会卡住动不了。

  • 相关阅读:
    简化单例模式
    static
    单例模式之懒汉模式
    Car race game
    poj-2403
    poj-2612
    poj-1833
    poj--2782
    poj--2608
    poj--3086
  • 原文地址:https://www.cnblogs.com/wanggang2016/p/13717648.html
Copyright © 2011-2022 走看看