// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Threading; namespace E { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } void AppendTextBox1(string msg) { textBox1.Text += (msg + "\r\n"); } //delegate void Handler(string s); void Run() { for(int i = 0; i < 10; i++) { string msg = "Dette er linie #" + i; if(textBox1.InvokeRequired) { //textBox1.Invoke(new Handler(AppendTextBox1), new object[] { msg }); textBox1.Invoke((MethodInvoker)delegate() { AppendTextBox1(msg); }); } else { AppendTextBox1(msg); } Thread.Sleep(2000); } } void Button1Click(object sender, EventArgs e) { (new Thread(Run)).Start(); } } }