how do I convert wpf dispatcher to winforms

前端 未结 1 1909
庸人自扰
庸人自扰 2020-12-11 20:51

I was moving over a method to my winforms project from a wpf project.

Everything but this section was moved without issue:

private void ServerProcErr         


        
1条回答
  •  攒了一身酷
    2020-12-11 21:16

    You should use Invoke to replace the 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);
        }
    }
    

    0 讨论(0)
提交回复
热议问题