zoukankan      html  css  js  c++  java
  • WPF UI 线程更新

    参考链接 https://blog.csdn.net/d100000/article/details/47971989?    实测有效

    Dispatcher x = Dispatcher.CurrentDispatcher; //获取当前的线程
    ThreadStart start = delegate ()  
    {
    Func<T> Result = new Func<T>(() => this.ShowBallLineCollection(ballLineCollectionHistory, false));//创建委托
    this.Dispatcher?.Invoke(Result);//执行  如果方法中有关于控件就得用 Dispatcher 执行 不然会报错
    x.BeginInvoke(new Action(() =>
    {
    this.expanderEndPlan.Content = Result();
    }), DispatcherPriority.Normal);
    };
    new Thread(start).Start();//启动线程


    之前写程序发现有一个方法运行时间很长,如果在wpf的UI线程的话,会等待很久,这样会造成使用的加大不便。

    于是想用线程来运行这个方法。

    可是在wpf中不能简单的使用thread,这样会出错,同事线程中不能相互使用元素。纠结了很久。

    最后找到一个简单实用的线程实现方式,就是实用task,或者func

  • 相关阅读:
    无限维
    黎曼流形
    why we need virtual key word
    TOJ 4119 Split Equally
    TOJ 4003 Next Permutation
    TOJ 4002 Palindrome Generator
    TOJ 2749 Absent Substrings
    TOJ 2641 Gene
    TOJ 2861 Octal Fractions
    TOJ 4394 Rebuild Road
  • 原文地址:https://www.cnblogs.com/xiaohezhong/p/14395130.html
Copyright © 2011-2022 走看看