We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Error loading GridControl on separate thread

Hi -
We are using a separate thread to load data into our grid control because it is loading during a dialog load and we don't want the dialog to wait for the data to load in the grid before it displays.

However, we periodicially get the following error and a big red X in the grid.

************** Exception Text **************
System.InvalidProgramException: Grid is in updating mode
at Syncfusion.Windows.Forms.Grid.GridControlBase.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at Syncfusion.Windows.Forms.ScrollControl.WmPaint(Message& msg)
at Syncfusion.Windows.Forms.ScrollControl.WndProc(Message& msg)
at Syncfusion.Windows.Forms.Grid.GridControlBase.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Any ideas of why this is happening? It doesn't happen everytime and is hard to reproduce.

Do you have a sample of how to properly multithread loading data into a gridcontrol in this environment? Note that we are using the latest version, .net 2.0 and that we load our grid cell by cell (this.Data[rowIndex, colIndex] = style.Store) in a grid which derives from GridControl.

Thanks,
Julie

14 Replies

HA haneefm Syncfusion Team April 26, 2007 07:51 PM UTC

Hi Julie,

When using multiple threads, note that any calls into the grid must be done on the thread that creates it, and you can use the grid.InvokeRequired to check for this.

See the following KB article for more details.
http://www.syncfusion.com/Support/article.aspx?id=572

If you still face the same issues, please send me a working sample so that we may work on it here for you.

Best regard,
Haneef


JL Julie Levy April 26, 2007 08:40 PM UTC

Hi Haneef -
thanks for your response. I didn't find the sample all that helpful because we don't load the grid using those events. I have supplied a simple sample with a form (frmMultiThread) which has a button which launches another form as a dialog that has a grid in it. I have not yet added the separate thread to load the grid. Could you show me what the proper implementation is and where to check grid.InvokeRequired and where the delegates should be.
Thanks,
Julie

Grid_MultiSelect3.zip


HA haneefm Syncfusion Team April 26, 2007 08:59 PM UTC

Hi Julie,

I am really sorry to inform you that I am not able to reproduce the issue in Essential version 4.4.0.51 with MS.Net 2.0. Maybe I am not following the steps that you are doing. Your attached sample working fine here. Can you tell me how to see it in the your attached sample?. This will help us to analyse the issue further.

Best regards,
Haneef


JL Julie Levy April 26, 2007 09:14 PM UTC

Hi Haneef -
The issue is hard to reproduce. What i sent you was just a simple form loading a dialog with a grid with no threading yet. I wanted you to show me the proper way to add it since the sample you sent me is very different from how we load our grid. So there is no threading yet in the sample i sent you.


HA haneefm Syncfusion Team April 26, 2007 10:43 PM UTC

Hi Julie,

One way you can try to test for this is to derive the grid and override OnCellsChanged, OnQueryCellInfoChanged,OnQueryColCount and OnQueryRowCount which are a method that is hit in the call stack you. In the override test to see if you are on the proper thread.

public class MySafeTyGridControl : GridControl
{
delegate void OnCellsChangedDelegate(GridCellsChangedEventArgs e);
protected override void OnCellsChanged(GridCellsChangedEventArgs e)
{
if(this.InvokeRequired)
{
OnCellsChangedDelegate cellDelegate = new OnCellsChangedDelegate(OnCellsChanged);
this.BeginInvoke(cellDelegate,new object[]{e});
}
else
base.OnCellsChanged (e);
}

delegate void OnQueryCellInfoDelegate(GridQueryCellInfoEventArgs e);
protected override void OnQueryCellInfo(GridQueryCellInfoEventArgs e)
{
if(this.InvokeRequired)
{
OnQueryCellInfoDelegate queryDelegate = new OnQueryCellInfoDelegate(OnQueryCellInfo);
this.BeginInvoke(queryDelegate,new object[]{e});
}
else
base.OnQueryCellInfo (e);
}

delegate void OnQueryColCountDelegate(GridRowColCountEventArgs e);
protected override void OnQueryColCount(GridRowColCountEventArgs e)
{
if(this.InvokeRequired)
{
OnQueryColCountDelegate queryColCountDelegate = new OnQueryColCountDelegate(OnQueryColCount);
this.BeginInvoke(queryColCountDelegate,new object[]{e});
}
else
base.OnQueryColCount (e);
}

delegate void OnQueryRowCountDelegate(GridRowColCountEventArgs e);
protected override void OnQueryRowCount(GridRowColCountEventArgs e)
{
if(this.InvokeRequired)
{
OnQueryRowCountDelegate queryRowCountDelegate = new OnQueryRowCountDelegate(OnQueryRowCount);
this.BeginInvoke(queryRowCountDelegate,new object[]{e});
}
else
base.OnQueryRowCount (e);
}
}

Please refer to the modifed attached sample for implementation.
ModifiedGrid_MultiSelect.zip

Best regards,
Haneef


JL Julie Levy April 26, 2007 11:36 PM UTC

Hi Haneef -
thanks for the code. I've added this and tested it and it seems like everytime time the InvokeRequired is false which i think means our thread is ok.
Can you think of anything else that would produce this error?
Thanks,
Julie


HA haneefm Syncfusion Team April 26, 2007 11:50 PM UTC

Hi Julie,

Thank you for your update.

The information that you have given is not sufficient to trace the issue. I am not sure of what be might be causing this strange behavior without a working sample. Is it possible for you to upload us a minimal sample to reproduce the issue here? This will help us to analyse the issue further.

Best regards,
Haneef


JL Julie Levy April 27, 2007 05:15 PM UTC

Hi Haneef -
sorry, but i can't even reproduce it on my machine. It's only happened on a few machines in our installed environment, not dev.
Thanks for your help,
Julie


JL Julie Levy May 3, 2007 09:31 PM UTC

Hi Haneef -
we created a sample which does show the problem if you play with it. Start frmMultiThread and launch the dialog and close it, etc. multiple times. We noticed the X and error mentioned above happens when you use the keyboard to launch the dialog (enter) and the following error happens when you use the mouse.

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
at System.Array.BinarySearch[T](T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
at Syncfusion.Windows.Forms.Grid.GridViewLayout.PointToClientCol(Point pt, Boolean fixBackHidden, GridCellSizeKind sizeKind)
at Syncfusion.Windows.Forms.Grid.GridResizeCellsMouseController.ResizeCellsHitTestInfo..ctor(GridResizeCellsMouseController resizeUI, GridControlBase grid, Point point, GridResizeCellsReason reason)
at Syncfusion.Windows.Forms.Grid.GridResizeCellsMouseController.HitTest(MouseEventArgs e, IMouseController controller)
at Syncfusion.Windows.Forms.MouseControllerDispatcher.HitTest(Point point, MouseButtons mouseButton, Int32 clicks, IMouseController& controller)
at Syncfusion.Windows.Forms.MouseControllerDispatcher.ProcessMouseMove(MouseEventArgs e)
at Syncfusion.Windows.Forms.ScrollControllMouseControllerDispatcher.ScrollControlMouseMoveHandled(Object sender, MouseEventArgs e)
at Syncfusion.Windows.Forms.ScrollControl.OnScrollControlHandledMouseMove(MouseEventArgs e)
at Syncfusion.Windows.Forms.ScrollControl.OnMouseMove(MouseEventArgs e)
at Syncfusion.Windows.Forms.Grid.GridControlBase.OnMouseMove(MouseEventArgs e)
at Syncfusion.Windows.Forms.Grid.GridControlBaseImp.OnMouseMove(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseMove(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at Syncfusion.Windows.Forms.ScrollControl.WndProc(Message& msg)
at Syncfusion.Windows.Forms.Grid.GridControlBase.WndProc(Message& msg)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



It's sporadic so you have to play with it a bit. We also added a screenshot of the UI (screenshot.bmp).

Thanks,
Julie

Grid_MultiSelect5.zip


JL Julie Levy May 3, 2007 09:33 PM UTC

oops, nevermind the mouse move error... we found that if we add theMouseMove delegate it doesn't happen.... but the X edit error still does.

Thanks,
Julie


JL Julie Levy May 7, 2007 11:20 PM UTC

Just wanted to clarify that the original exception at the top of the post is happening in the sample i provided.
Thanks,
Julie


JL Julie Levy May 8, 2007 09:16 PM UTC

I need a response so i have logged an incident.


LD ldjiba April 4, 2018 10:11 AM UTC

Yes


SN Sindhu Nagarajan Syncfusion Team April 5, 2018 04:33 AM UTC

Hi ldjiba, 
 
Thanks for the update. 
 
Please let us know if you need  any further assistance on this. 
 
Regards, 
Sindhu  


Loader.
Live Chat Icon For mobile
Up arrow icon