6

メソッドを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);
  }));
}

winformsに変換する方法がわかりませんDispatcher

誰でも私を助けることができますか?

4

1 に答える 1

12

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);
    }
}
于 2013-08-08T19:52:43.747 に答える