zoukankan      html  css  js  c++  java
  • WPF 线程间访问控件

    lisClient.Dispatcher.Invoke(new Action(() => { lisClient.Items.Add(socket.RemoteEndPoint.ToString()); }));
    string strmsg=(string)txtSMsg.Dispatcher.Invoke(new Func<string>(() =>
    {
        return txtSMsg.Text; // 返回txtSMsg的text信息
    }));

    一小段代码如上  是我在写多线程的通讯的时候用到的代码。

    和winform下的有一些区别,wpf下要创建 Dispatcher 的线程才可以直接访问,还是使用Invoke ,在这里直接使用的Action和 Func  对于简短的操作 个人认为使用这两个比较好些,个人见解 还请指教。

  • 相关阅读:
    37.js----浅谈js原型的理解
    iOS
    iOS
    iOS
    python3
    ios
    iOS
    python3
    python3
    iOS
  • 原文地址:https://www.cnblogs.com/yahue/p/2576994.html
Copyright © 2011-2022 走看看