Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ex = {"Cross-thread operation not valid: Control 'dataGridView1' accessed from a thread other than the thread it was created on."}

Posted on 2006-07-17
5
Medium Priority
?
1,626 Views
Last Modified: 2008-01-09
this should be a good one!

I need some help, i basically have a winform with a gridview on it. What happens is that the user selects a folder with some images in it and then the images load into a datagridview. the issue is that when they take high res pics and there are more than a couple the form locks while the pictures are loaded. I want to try keep their blood pressure down as they dont have high spec machines, so i wanted to implement a multi thread scenario. i would like a child thread to load the images into the grid and update a progress bar while they still have a responsive gui.... i am fine with loading the pics and progress bar ... its the child thread accessing the controls in the main application thread.

there is actually a lot of info on this on the web error message, I am am sure that i will have to spend a few hours reading this up. I have vs 2005 (net 2.0) but have mainly been working with asp.net, i have a solid .net 1.1 book that i might have to dust the cob webs off to see if there are some examples child threads accessing cross threads controls (resources).

I need advice, i have already read about this sort of thing but not realy sure what is going on....                
if (Control.InvokeRequired)
                {
                      Control.Invoke(new MethodInvoker(Control.Hide()));
                }

if there is some code examples then much appreciated!! I have read some msdn example which are excellent but they go a bit over my head...
0
Comment
Question by:deanvanrooyen
  • 4
5 Comments
 
LVL 12

Author Comment

by:deanvanrooyen
ID: 17127503
ps. thanks
0
 
LVL 12

Author Comment

by:deanvanrooyen
ID: 17127518
I notice there is a background worker control -  how is this different to say creating my own thread -

                Thread myThread = new Thread(new ThreadStart(MyFunction));
                myThread.Priority = ThreadPriority.AboveNormal;
                if (!myThread.IsAlive)
                    myThread.Start();
0
 
LVL 12

Author Comment

by:deanvanrooyen
ID: 17127637
well well,

I get the same error cross thread usin the backgroundworker ... I took the example straight out msdn, and it failing because what I do it I put a progress bar into a toolstrip in the child thread / background worker
like so

                //setup progress
                ProgressBar progressBar1 = new ProgressBar();
                progressBar1.Height = 10;
                progressBar1.Width = 100;
                ToolStripControlHost host = new ToolStripControlHost(progressBar1, "Progress");
                toolStrip1.Items.Insert(7, host);

Cross-thread operation not valid: Control toolStrip1 accessed from a thread other than the thread it was created on."}
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 17127783
0
 
LVL 12

Author Comment

by:deanvanrooyen
ID: 17127998
I sorted it actually this is a very good eg in ms help
//ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/138f38b6-1099-4fd5-910c-390b41cbad35.htm


you gets the points for quick assist thanks


0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

927 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