C# 调用什么?

C# 调用什么?,c#,visual-studio,invoke,C#,Visual Studio,Invoke,什么是方法调用,control.invoke 编程中通常调用什么 示例: MethodInvoker getValues = new MethodInvoker(delegate() { checkbox1Checked = checkbox1.Checked; textBox6Text = textBox6.Text; textBox7Text = textBox7.Text; textBox3Text = textBox3.Text; textBox1

什么是方法调用,control.invoke

编程中通常调用什么

示例:

MethodInvoker getValues = new MethodInvoker(delegate()
{
    checkbox1Checked = checkbox1.Checked;
    textBox6Text = textBox6.Text;
    textBox7Text = textBox7.Text;
    textBox3Text = textBox3.Text;
    textBox1Text = textBox1.Text;
    textBox4Text = textBox4.Text;
    richTextBox1Text = richTextBox1.Text;
    textBox5Text = textBox5.Text;
});

if (this.InvokeRequired)
{
    this.Invoke(getValues);
}
else
{
    getValues();
}

我还想知道MethodInvoker和InvokerRequired是什么意思?

“调用”指调用一个方法

在winforms中,
Control.Invoke
用于调用UI线程上的方法-没有它,您可以通过从另一个线程更新UI来导致异常


因此,如果
invokererequires
返回
true
,这意味着您没有在UI线程中运行,应该使用
Control.Invoke
在正确的线程中运行调用。

此外,您可能希望使用异步版本-
BeginInvoke
请参阅