DoEvents adding GetInputState to improve performance


I have code that reads 1000 sql records and outputs the data to a datagrid.

Normally the program looks like its "hung" until the sql code has finished.

However I found the "DoEvents" function which I added, after each record has been returned, as follows:-

invoke type "System.Windows.Forms.Application"::"DoEvents"()

This works and looks a lot better but it has really slowed down the program.

So I then found the following VB code but have no idea how to convert to Cobol code, can any one pls advise.

Private Declare Function GetInputState Lib "user32" () As Integer

Private Sub btnGetInputState_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetInputState.Click
'This loop uses the GetInputState() Api call to check if any
'messages needs to be processed and decides whether or not to
'execute the DoEvents() method. Your application will NOT appear to
'be frozen while the code is running.
'You save ALOT of time by using the GetInputState api call to check
'whether any messages needs to be processed first. The DoEvents()
'method is ONLY fired when there ARE messages that needs to be
'processed, thus really increasing the performance of your
'application. This is definitely the BEST way to allow the user to
'still interact with your program while the code is still
Dim i As Integer = 0


'just a meaningless loop to use for testing the performance
For i = 0 To 4000000

    'if it returns 0, then there are NO keyboard or mouse messages
    'queued in the thread
    If Not GetInputState = 0 Then Application.DoEvents()

'the code below is for calculating the time it took to fully
'execute the loop

timeSpeed = (endTime - startTime) / timerFreq

lblGetInputState.Text = "GetInputState(): " & timeSpeed.ToString & _
" sec(s)"

MessageBox.Show("Done executing the Loop!", " Code is finished!", _
MessageBoxButtons.OK, MessageBoxIcon.None)

End Sub

Parents Reply Children
No Data