Solved

Cross-thread operation not valid - Treeview

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 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