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

  • 相关阅读:
    程序员都必读
    ia-64 vs x86-64
    Linux内核学习
    开源liscense对比
    列存储
    大数据科普
    [USACO1.5]数字三角形
    [USACO08FEB]酒店Hotel
    数的划分
    CodeForce 18D
  • 原文地址:https://www.cnblogs.com/wanggang2016/p/13717648.html
Copyright © 2011-2022 走看看