Solved

Screen redraaw problem

Posted on 2009-04-11
7
225 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

22 Experts available now in Live!

Get 1:1 Help Now