Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Details:
Cross thread operation not valid control combobox accessed from a thread other than the thread it was created on.

i am checking if(combobox.selectedindex==0)in event to do other operation but exception was raising .any suggestions to avoid this exception
Posted

1 solution

You need to use Invoke or BeginInvoke method of Control or Dispatcher.

You will find enough detail in my past Answers:
Control.Invoke() vs. Control.BeginInvoke()[^]
Problem with Treeview Scanner And MD5[^]

For more information:
How to get a keydown event to operate on a different thread in vb.net[^]

The applications of the Inquirers are all different, but you need to understand Invocation, first of all.
No calls to any members of UI classes can be done from any threads except the UI thread (in WPF, too). Invocation mechanism put all data and delegate instance needed to the call in the queue. The actual call is always done in UI thread, that's it.

—SA
 
Share this answer
 
v2
Comments
Olivier Levrey 16-Mar-11 5:52am    
Sure. My 5.
Sergey Alexandrovich Kryukov 16-Mar-11 12:00pm    
Thank you, Olivier,
--SA
Nuri Ismail 16-Mar-11 8:40am    
Good call! My 5.
Sergey Alexandrovich Kryukov 16-Mar-11 12:01pm    
Thank you, Nuri,
--SA
Albin Abel 16-Mar-11 8:55am    
My 5 too

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900