Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

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
0
jindalee
Asked:
jindalee
  • 4
  • 3
1 Solution
 
Fernando SotoCommented:
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
 
Fernando SotoCommented:
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
jindaleeAuthor Commented:
That did the trick.  Any chance you could explain why?
0
 
Fernando SotoCommented:
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 SotoCommented:
Not a problem, I understand, glad I was able to help.  ;=)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now