public void appendText(string msg) { if (this.msgHst.InvokeRequired) { appendTextCallback d = new appendTextCallback(appendText); this.Invoke(d, new object[] { msg }); } else { this.msgHst.AppendText(Environment.NewLine + msg); } }
private void AppendConsoleText(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.textBoxOutput.InvokeRequired) { appendTextCallback d = new appendTextCallback(AppendConsoleText); this.Invoke(d, new object[] { text }); } else { this.textBoxOutput.AppendText(text); } }
void appendText(Control control, string text) { if (control.InvokeRequired) { appendTextCallback d = new appendTextCallback(appendText); this.Invoke(d, new object[] { control, text }); } else { string line = $"{DateTime.Now}: {text}\r\n"; var method = control.GetType().GetMethod("AppendText"); if (method != null) { method.Invoke(control, new object[] { line }); } method = control.GetType().GetMethod("Update"); if (method != null) { method.Invoke(control, null); } } }