Kai,
I don't think the problem has anything to do with that exception.
Instead, what I think is happening is that when you call DoEvents with some grid's WM_PAINT messages pending, the DoEvents comes across a WM_PAINT for the grid. So, it tells the grid to process the WM_PAINT, but the grid just ignores the WM_PAINT because of the BeginUpdate call. So, DoEvents again tells the grid to handle the SAME ignored WM_PAINT, and an endless loop is born.
I discussed this problem with Stefan, and he will look into it when he has time. But during the BeginUpdate/EndUpdate, the idea was to let these WM_PAINT messages remain in the message queue so they would eventually be handled when EndUpdate was done. Of course, this will not work if from a DoEvents handler. But changing it, may impact other things.
I think there is a straight-forward workaround. The idea is to note when you are in a DoEvents loop, and if so, then don't ignore the grid's WM_PAINT.
To do this, add a public static member to some class that you can use to mark when you are in a DoEvents loop.
public static bool InDoEvents = false;
private void button1_Click(object sender, System.EventArgs e)
{
this.gridControl1.BeginUpdate();
this.gridControl1.Refresh();
Console.WriteLine("before Application.DoEvents");
Form1.InDoEvents = true;
Application.DoEvents();
Form1.InDoEvents = false;
Console.WriteLine("after Application.DoEvents");
this.gridControl1.EndUpdate();
}
Then override the grid's WndProc and process the WM_PAINT if you are in the DoEvents loop.
public class MyGridControl : GridControl
{
public const int WM_PAINT = 15;
protected override void WndProc(ref System.Windows.Forms.Message msg)
{
if(Form1.InDoEvents && msg.Msg == WM_PAINT)
DefWndProc(ref msg);
else
base.WndProc(ref msg);
}
}
One other comment is that if you want to have a progress bar on a different thread, then there is such a bar in the Shared library. If you look at the GridPopulationSample that ships with the grid, it uses it to put up a prgress bar if something is taking a long time (lik eusing the Indexer method to populate a 1000x1000 grid).