c# - Cross-thread operation not valid - listbox Clear statement -


i getting error because trying update listbox thread not created on:

cross-thread operation not valid: control 'tbhistory' accessed thread other

thread t = new thread(updatehistory);          // kick off new thread t.start();  private void updatehistory() { //tbhistory listbox tbhistory.items.clear(); } 

can please give me code fix problem? know supposed use invoke examples found on google don't seen me. examples seem show how change label text, not clear listbox.

you need use ui thread. accomplish this, use:

private void updatehistory() {    //tbhistory listbox    myform.invoke ((action) (() =>tbhistory.items.clear())); } 

edit: added missing bracket code wouldn't compile.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -