我怎么转换WPF调度员的WinForms [英] how do I convert wpf dispatcher to winforms
本文介绍了我怎么转换WPF调度员的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被感动了,从一个WPF项目我WinForms项目的方法。
I was moving over a method to my winforms project from a wpf project.
一切,但是这部分没有问题,很感动:
Everything but this section was moved without issue:
private void ServerProcErrorDataReceived(object sender, DataReceivedEventArgs e)
{
// You have to do this through the Dispatcher because this method is called by a different Thread
Dispatcher.Invoke(new Action(() =>
{
richTextBox_Console.Text += e.Data + Environment.NewLine;
richTextBox_Console.SelectionStart = richTextBox_Console.Text.Length;
richTextBox_Console.ScrollToCaret();
ParseServerInput(e.Data);
}));
}
我不知道如何转换了调度
来的WinForms。
I have no idea how to convert over Dispatcher
to winforms.
任何人都可以帮我吗?
Can anyone help me out?
推荐答案
您应该使用的 调用
来替换调度
。
private void ServerProcErrorDataReceived(object sender, DataReceivedEventArgs e)
{
if (richTextBox_Console.InvokeRequired)
{
richTextBox_Console.Invoke((MethodInvoker)delegate
{
ServerProcErrorDataReceived(sender, e);
});
}
else
{
richTextBox_Console.Text += e.Data + Environment.NewLine;
richTextBox_Console.SelectionStart = richTextBox_Console.Text.Length;
richTextBox_Console.ScrollToCaret();
ParseServerInput(e.Data);
}
}
这篇关于我怎么转换WPF调度员的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文