1

i have a Grid in WindowsForms called grid1.

i know want to call grid1.Series.Clear() from another thread.

Right now i am getting the usual cross thread exception that a thread is touching grid1 but another thread created it.

I find plenty of examples how to call direct functions of grid1.

But how to do it with Calling Clear() Function from SeriesCollection "Series" within grid1?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
tuxmania
  • 906
  • 2
  • 9
  • 28

3 Answers3

2

Something like the following:

grid1.BeginInvoke(new MethodInvoker(() => grid1.Series.Clear()));
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
1

Maybe this will help.

If you wanna create a function for that, this is an example.

delegate void FunctionNameCallBack(InputParams);
private void FunctionName(InputParams)
{
    if (this.InvokeRequired)
    {
        var d = new FunctionNameCallBack(FunctionName);
        this.Invoke(d, InputParams);
    }
    else
    {
        // Your Code here.
    }
}
MSL
  • 990
  • 1
  • 12
  • 28
0

This code is run on a thread other than the thread which created the grid1 control

grid1.Invoke((MethodInvoker)(() => grid1.Series.Clear()));
H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Mark
  • 101
  • 1
  • 7