Highlighted
Absent Member.
Absent Member.
4375 views

DoEvents adding GetInputState to improve performance

Jump to solution

Hi,

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
'executing.
'
Dim i As Integer = 0

QueryPerformanceCounter(startTime)

'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()

Next
'
'the code below is for calculating the time it took to fully
'execute the loop
'
QueryPerformanceCounter(endTime)

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

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: DoEvents adding GetInputState to improve performance

Jump to solution

Thanks Stephen.

Yes, sorry I had the call WINAPI in my original example and then removed it for a test and then did a copy/paste without it. Whoops.

Should look like:

Example:

      program-id.
      Program1 as "testgetinputstate.Program1".      
      special-names.         
            call-convention 66 is winapi.      
      data division.      
      working-storage section.      
      01 mybool   pic S9(9) comp-5.      
      01 pp       procedure-pointer.       
      procedure division.          
           set pp to entry "user32"          
           call winapi "GetInputState" returning mybool           
           if mybool = 0             
              display "no messages"          
           else
             display "messages in Queue"
          end-if          
          goback

 

View solution in original post

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: DoEvents adding GetInputState to improve performance

Jump to solution

GetInputState is a Windows API function in the User32.dll.

You can call it like you would any Windows API function but if you are calling from managed code then you will have to load the .dll first.

Example:

      program-id. Program1 as "testgetinputstate.Program1".
      special-names.
         call-convention 66 is winapi.
      data division.
      working-storage section.
      01 mybool   pic S9(9) comp-5.
      01 pp       procedure-pointer.
      procedure division.
          set pp to entry "user32"
          call "GetInputState" returning mybool
          if mybool = 0
             display "no messages"
          else
             display "messages in Queue"
          end-if
          goback.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: DoEvents adding GetInputState to improve performance

Jump to solution

Chris,

The GetInputState is WINAPI, so you need to use 'call WINAPI "GetInputState" returning mybool'

msdn.microsoft.com/.../ms644935(v=vs.85).aspx

--

Stephen

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: DoEvents adding GetInputState to improve performance

Jump to solution

Thanks Stephen.

Yes, sorry I had the call WINAPI in my original example and then removed it for a test and then did a copy/paste without it. Whoops.

Should look like:

Example:

      program-id.
      Program1 as "testgetinputstate.Program1".      
      special-names.         
            call-convention 66 is winapi.      
      data division.      
      working-storage section.      
      01 mybool   pic S9(9) comp-5.      
      01 pp       procedure-pointer.       
      procedure division.          
           set pp to entry "user32"          
           call winapi "GetInputState" returning mybool           
           if mybool = 0             
              display "no messages"          
           else
             display "messages in Queue"
          end-if          
          goback

 

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.