c# - ContextSwitchDeadLock after changing ListViewItem property from another Thread -


i struggling whole day now.

this how start thread

new thread(() => myfunction()).start(); 

myfunction() ends piece of code update gui's listview:

utilities.mainform.invoke(new action(() => {     utilities.mainform.updatesearches(); })); 

i have tried begininvoke.

utilities.mainform set this in mainform's constructor. it's static property of utilities use current instance of form.

in updatesearches() retrieve new data database , refill listview so

lstsearches.items.clear(); lstsearches.items.addrange((listviewitem[])listitems.toarray(typeof(listviewitem))); 

all more surprised next action leads crash (contextswitchdeadlock).

if (selectedindex >= 0 && lstsearches.items.count > selectedindex) {     lstsearches.items[selectedindex].selected = true;     //lstsearches.select(); } 

selectedindex means index in lstsearches selected , index exist, checked that. can set index 0, like

lstsearches.items[selectedindex].selected = true; 

and line crash application, when called through invoke. if put return before this, things work, else whole gui freezes etc. once put debugger.break() before , changed selected property true in visual studio (i hope know mean, it's when hover object , window opens , can see , set properties/ methods). in moment changed false true , pressed enter - same happened, freezes , contextswitchdeadlock.

this happens when called invoke construction oddly enough there no problems manipulating form controls in code above.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -