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
1,624 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

623 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