Solved

Cross-thread operation not valid - Treeview

Posted on 2011-03-17
3
798 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

24 Experts available now in Live!

Get 1:1 Help Now