Ero*_*ocM 4 c# wpf dispatcher winforms
我正在从一个wpf项目转移到winforms项目的方法.
除了这一部分之外的所有内容都没有问题:
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);
}));
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何转换Dispatcher为winforms.
谁能帮我吗?
Shi*_*rod 10
你应该Invoke用来替换Dispatcher.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7262 次 |
| 最近记录: |