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
Post a Comment