본문 바로가기

Programming/C# Sample Code

[ Programming_C# Sample Code ] Thread, Delegate Return

Thread에서 UI Control에 접근 시에 Delegate를 이용하여 접근해야되는데, 값 Setting은 해봤지만 Get은 안해봤다...ㅜㅜ 결국 해야될 일이 생기고, 찾다가 알게된 내용!

private delegate string GetTextBoxCallback(TextBox tbTxtBox);

private string GetTextBox(TextBox tbTxtBox)
{
    if (this.tbTxtBox.InvokeRequired)
    {
        GetTextBoxCallback GetTextBoxCB = new GetTextBoxCallback(GetTextBox);
        return (string) this.InvokeGetTextBoxCB, new object[] { tbTxtBox });
    }
    else
    {
        return tbTxtBox.Text;
    }
}


중요한건 Invoke 요청시 꼭 return (리턴타입)으로 해야됨!!!