Created
February 7, 2012 16:13
-
-
Save jacking75/1760474 to your computer and use it in GitHub Desktop.
C# - 다중 스레드에서 컨트롤을 변경 할 때
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from : MSDN | |
// 델리게이트를 선언한다. | |
delegate void SetTextCallback(string text); | |
// 컨트롤의 접근은 따로 함수를 만들어서 접근하도록 한다. | |
private void SetText(string text) | |
{ | |
// InvokeRequired required compares the thread ID of the | |
// calling thread to the thread ID of the creating thread. | |
// If these threads are different, it returns true. | |
if (this.textBox1.InvokeRequired) | |
{ | |
SetTextCallback d = new SetTextCallback(SetText); | |
this.Invoke(d, new object[] { text }); | |
} | |
else | |
{ | |
this.textBox1.Text = text; | |
} | |
} | |
//스레드에서 아래 함수를 호출하면 된다. | |
SetTextCallback(SetText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment