c# - Cross-thread operation not valid -


possible duplicate:
cross-thread operation not valid: control accessed thread other thread created on

okay, know why giving me error:

cross-thread operation not valid: control 'form1' accessed thread other thread created on.

but... how can make workable?

system.threading.thread t = new system.threading.thread(()=> {    // hard work , then...    listview1.items.add(lots of items);    lots more ui work }); t.start(); 

i don't care when, or how thread finishes, don't care fancy or on complicated atm, unless it'll make things easier when working ui in new thread.

you can't. ui operations must performed on owning thread. period.

what could do, create items on child thread, call control.invoke , databinding there.

or use backgroundworker

    backgroundworker bw = new backgroundworker();     bw.dowork += (s, e) => { /* create items */ };     bw.runworkercompleted += (s, e) => { /* databind ui element*/ };      bw.runworkerasync(); 

Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

java - Getting corefrences with Standard corenlp package -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -