vb.net - Getting a listbox item value safely in a thread -
hi have program run threads , updates ui in process. have used .invokerequired safe threading , running ok. in 1 of threads necessary use value of item in listbox created in thread (listbox2.items(index))
, i'm doing dim item1 integer =listbox2.items(index)
. program running fine , showing no exceptions or error messages, however, if add watch of same line following message + accessibilityobject {"cross-thread operation not valid: control 'listbox2' accessed thread other thread created on."} system.invalidoperationexception.
is normal? there way safely value of item in listbox located on thread?
to answer question cross thread exception, normal , not allowed access ui elements different thread 1 created on. fix need use control.invoke() execute lambda expression run access code on thread created listbox.
dim item1 integer if listbox2.invokerequired listbox2.invoke(sub() item1 = listbox2.items(index)) else item1 = listbox2.items(index) end if
Comments
Post a Comment