没有调度员的定义

Ker*_*mit 0 c# dispatcher winforms

我收到了错误

'socketServer.Form1'不包含'Dispatcher'的定义,并且没有扩展方法'Dispatcher'接受类型为'socketServer.Form1'的第一个参数'

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

根据文档,Dispatcher该类是System.Windows.Threading我正在使用的命名空间的一部分.

我错过了另一个参考吗?

如果它是相关的,我在使用服务器/客户端套接字收到"跨线程操作无效"的错误后添加了这个.

und*_*ned 9

WinForms中没有Dispatcher.

为了发布异步UI更新(这正是做什么Dispatcher.BeginInvoke),只需使用 this.BeginInvoke(..)它是Control基类中的方法.在你的情况下你可以有这样的东西(从MSDN 模式采用):

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

如果要进行同步更新,请使用 this.Invoke