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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Why does the call to Application.DoEvents never returns while updating the Grid using BeginUpdate() method

If the Grid is performing a time-consuming task, BeginUpdate() and EndUpdate() methods will be used to ensure the updates correctly reflected in the grid.

The problem arises when users try to dispatch windows messages to the controls (triggering the Application.DoEvents) inside BeginUpdate() and EndUpdate() methods.

Problem

The root cause of the problem is that the usage of Application.DoEvents will ask WM_PAINT messages of Grid to execute, but WM_PAINT messages will be ignored since the grid is in an updating state (the WM_PAINT message will be processed by the Grid only when the EndUpdate is called). Hence the above makes an Infinite loop execution, meaning the loop will never be returned from WM_PAINT.

The above problem can be resolved in the following two ways:

Solution 1

If the usage of Application.DoEvents is mandatory, then the simplest way to get rid of this problem is by calling the grid.CancelUpdate before triggering Appplication.DoEvents. After that, the grid can be updated with the call to Grid.BeginUpdate.

Solution 2

Add a public static member to the class where Application.DoEvents is to be used. Then override the Grid’s WndProc method and process WM_PAINT if the DoEvents loop is triggered.

 

Code Snippet

C#

 

VB

 

Sample links

C# Application.DoEvents_CS

VB Application.DoEvents_VB

 

 

Article ID: Published Date: Last Revised Date: Platform: Control:
6848 05/13/2016 05/13/2016 WinForms GridControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon