Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,625 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

688 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