Screen redraaw problem

When I select a menu item to kick off a CPU intensive process, the process runs showing the progress dialog.

However, the menu remains displayed until the process has completed. (You can see what I mean in the attached image.)

How do I ensure that the menu disappears before the process kicks off?
ScreenError.jpg
LVL 1
jindaleeAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Try adding this line, Application.DoEvents(), to the code as shown in the code snippet.
   Private Sub ProgramsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgramsToolStripMenuItem.Click
        DataGridView1.Rows.Clear()
        fontCount = 0
        dlgLoadProgress.Text = My.Resources.searchExecutableFile.ToString()
        fileType = "*.exe"
        Application.DoEvents()   ' Add this line here
        dlgLoadProgress.Show()
        GetFiles(fileType)
        dlgLoadProgress.Close()
    End Sub

Open in new window

0
 
Fernando SotoRetiredCommented:
Can you post the menu click event that kicks off the CPU intensive process?
0
 
jindaleeAuthor Commented:
Here it is (in full):
   Private Sub ProgramsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgramsToolStripMenuItem.Click
        DataGridView1.Rows.Clear()
        fontCount = 0
        dlgLoadProgress.Text = My.Resources.searchExecutableFile.ToString()
        fileType = "*.exe"
        dlgLoadProgress.Show()
        GetFiles(fileType)
        dlgLoadProgress.Close()
    End Sub

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jindaleeAuthor Commented:
That did the trick.  Any chance you could explain why?
0
 
Fernando SotoRetiredCommented:
What was happening is that the Window events that display and redraw the visuals on the screen were in the Windows Message Loop ready to be processed when the menu click event was called. This transfers control to the menu click event and does not return to process the remaing events until the menu click event has completed. By issueing a Application.DoEvents() this tells the OS to complete the processing of the events in the Windows Message Loop and return to the menu click event when that is done.
0
 
jindaleeAuthor Commented:
Thank you. It is much better to understand what is happening than to just accept that it does the trick
0
 
Fernando SotoRetiredCommented:
Not a problem, I understand, glad I was able to help.  ;=)
0
All Courses

From novice to tech pro — start learning today.