问题描述
我遇到错误
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
这篇关于调度员没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!