Solved

Cross-thread operation not valid - Treeview

Posted on 2011-03-17
3
792 Views
Last Modified: 2012-06-27
Hi,

I've used 'the wizard' to convert a VB app created VS2003 to .Net 3.5 using Visual Studio 2010.  On running it everything seems to work (at least the core app, I've stripped out a few old bits and pieces for now) but I am getting an error with the Treeview control (called ProcessTree) - I haven't looked too far into this but I'd see if anyone could give me an easy explanation first ?

Error description -

"
Cross-thread operation not valid:
Control 'ProcessTree' accessed from a thread other than the thread it was created on.

"
Thanks.
0
Comment
Question by:gringogordo
3 Comments
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 100 total points
ID: 35158787
UI controls can only be manipulated from the UI Thread.  In your case, it seems that a background worker thread is doing something with ProcessTree, which is causing the exception.  Another scenario for this error occurs when the background thread creates the control and the UI Thread tries to use it.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 150 total points
ID: 35159100
Can you show the code that is causing the error?

VS2003 actually ignored this type of coding error.

You several options:
(1) Turn off this type of checking. *not recommended*
(2) Use manual Delegates and Invoke() to fix the problem.
(3) Use newer threading constructs such as the BackgroundWorker().
(4) Use a SynchronizationContext() to do the udpates.
0
 

Author Closing Comment

by:gringogordo
ID: 35164856
Thanks very much.  I hope the points allocaton is okay.  Points for 1st and points for advice!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now