调度员没有定义 [英] no definition for dispatcher

查看:63
本文介绍了调度员没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到错误


'socketServer.Form1'不包含'Dispatcher'的定义,也没有扩展方法'可以找到

'socketServer.Form1' does not contain a definition for 'Dispatcher' and no extension method 'Dispatcher' accepting a first argument of type 'socketServer.Form1' could be found

From

private void tbAux_SelectionChanged(object sender, EventArgs e)
{
    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate()
    {
        textBox.Text = tbAux.Text;
    }
    );
}

根据文档 Dispatcher 类是其中的一部分我正在使用的名称空间 System.Windows.Threading

According to the documentation, the Dispatcher class is part of the namespace System.Windows.Threading, which I'm using.

我缺少其他参考吗?

如果相关,我在收到使用服务器/客户端套接字的跨线程操作无效错误后添加了此内容。

In case it's relevant, I added this after receiving an error that "cross-thread operation was not valid" using a server/client socket.

推荐答案

WinForms中没有 Dispatcher

WinForms does not have a Dispatcher in it.

要发布异步UI更新(这正是 Dispatcher.BeginInvoke 所做的事情),只需使用 this.BeginInvoke(..)这是 Control 基类的方法。
您的情况可能是这样的(从MSDN 模式):

In order to post asynchronous UI update( that's exactly what Dispatcher.BeginInvoke does), just use this.BeginInvoke(..) It's a method from Control base class. In your case you could have something like this (adopted from MSDN pattern):

private delegate void InvokeDelegate();
private void tbAux_SelectionChanged(object sender, EventArgs e)
{
   this.BeginInvoke(new InvokeDelegate(HandleSelection));
}
private void HandleSelection()
{
   textBox.Text = tbAux.Text;
}

如果要同步更新,请使用 this。调用

If you want a synchronous update, use this.Invoke

这篇关于调度员没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆