private void AddTextToLog(string text) { if (RTB_Log.InvokeRequired) { AddTextCallBack stcb = new AddTextCallBack(AddTextToLog); this.Invoke(stcb, new object[] { text }); } else { RTB_Log.Text += "\n" + text + "\n"; } }
delegate void AddTextCallBack(string str); //로컬함수가 아닌 함수의 포인터 private void AddText(string str) { //스레드는 form1에 직접 액세스 X, 그래서 콜백할 수 있게 만들어주는 것 if (this.tbMemo.InvokeRequired) { AddTextCallBack d = new AddTextCallBack(AddText); this.Invoke(d, new object[] { str }); } else { tbMemo.Text += str; } }
delegate void AddTextCallBack(string str); //로컬함수 아님 //delegate: 함수의 포인터 -> 함수의 주소만 참조해서 호출 private void AddText(string str) { if (this.tbMemo.InvokeRequired) { AddTextCallBack d = new AddTextCallBack(AddText); this.Invoke(d, new object[] { str }); } else { tbMemo.Text += str; } }
public void AddText(string text) { if(richTextBox1.InvokeRequired) { AddTextCallBack t = new AddTextCallBack(AddText); this.Invoke(t, new object[] {text} ); } else { richTextBox1.AppendText(text + Environment.NewLine); richTextBox1.ScrollToCaret(); } }