if (listBox1.InvokeRequired) { listBox = new StringBuilder(this.listBox1.Text); }
This is the code in c# which when exec
Your code should run when InvokeRequired is false
delegate void SetListBoxDelegate(); void SetListBox() { if(!InvokeRequired) { listBox = new StringBuilder(this.listBox1.Text); } else Invoke(new SetListBoxDelegate(SetListBox)); }
Edit: Check out Making Windows Forms thread safe