C#C
C#3y ago
Gibbo

❔ updating a DGV from another form on another thread

hi all,
I'm wondering if you can help me with an issue I'm having updating a DGV.

I'm getting a thread operation error as below:

Cross-Thread operation not valid: Control 'dvgUSBDongles' accessed from a thread other than the thread it was created on

Now I understand why I'm getting this and its because the form I'm trying to access it on was generated from a BackgroundWorker(so on a seperate thread) but im not too clued up on this currently and am unsure how to fix it. Everything ive done so far ive managed to do from from alot of googling. but threads/threading is just meh!!!!

this is my code:

                if (InvokeRequired == true)
                {
                    Invoke(new Action(() => {      mainformFunctions.RefreshData(); }));
                    Invoke(new Action(() => { this.Close(); }));
                }
                else
                {
                    mainformFunctions.RefreshData();
                    this.Close();
                }
Was this page helpful?