Solved

Screen redraaw problem

Posted on 2009-04-11
7
211 Views
Last Modified: 2013-11-27
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
Comment
Question by:jindalee
  • 4
  • 3
7 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 24124413
Can you post the menu click event that kicks off the CPU intensive process?
0
 
LVL 1

Author Comment

by:jindalee
ID: 24124424
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
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 24124447
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Closing Comment

by:jindalee
ID: 31569260
That did the trick.  Any chance you could explain why?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 24125566
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
 
LVL 1

Author Comment

by:jindalee
ID: 24128355
Thank you. It is much better to understand what is happening than to just accept that it does the trick
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 24132075
Not a problem, I understand, glad I was able to help.  ;=)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now