2011-07-31 2 views
7

메소드 호출, 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 및 InvokeRequired가 무슨 뜻 알지?

+0

http://stackoverflow.com/questions/14703698/c-invokedelegate에서 아주 좋은 답변보기 – Hlina

답변

11

"호출"은 메서드 호출을 나타냅니다.

winforms에서 Control.Invoke은 UI 스레드에서 메서드를 호출하는 데 사용됩니다. UI 스레드를 사용하지 않으면 다른 스레드에서 UI를 업데이트하여 예외가 발생할 수 있습니다.

InvokeRequirestrue이면 UI 스레드에서 실행 중이 아니며 Control.Invoke을 사용해야 올바른 스레드에서 호출을 실행할 수 있습니다.

+0

또한 비동기 버전 인 'BeginInvoke' – Poma