Solved

Screen redraaw problem

Posted on 2009-04-11
7
226 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

12 Experts available now in Live!

Get 1:1 Help Now