Re: Why do windows go blank?
- From: "Joe User" <joeu2004>
- Date: Fri, 11 Dec 2009 16:39:41 -0800
"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote:
Sleep won't help
Why do think so?
I am referring to the kernel interface. I have verified that the time
elapsed across the Sleep call is indeed about 100 msec (for Sleep 100), give
or take a few msec (which is understandable).
It happens because VBA is working hard and gives
no chance to update the interface.
I don't think so.
For your edification, try running the macro below while Task Manager is open to the Performance tab. It clearly shows a square wave with alternating cycles of 100% and near-0% CPU utilization. QED.
Don't forget to close all windows except Excel, VBA and Task Manager. I also minimize the Excel window.
maybe you can use Application.OnTime instead.
Why do you think OnTime would have any better behavior than Sleep?
Besides, I indicated the need for msec resolution (originally 30; now 100). I believe OnTime has a 1-sec resolution. In order to get the same "duty cycle", the CPU-intensive macro would have to run for 10 sec before blocking for 1 sec using OnTime. I think that would exacerbate the problem, whatever it is.
Public Declare Sub Sleep Lib "kernel32" (ByVal msec As Long)
Public Declare Function QueryPerformanceFrequency Lib _
"kernel32" (ByRef freq As Currency) As Boolean
Public Declare Function QueryPerformanceCounter Lib "kernel32" _
(ByRef cnt As Currency) As Boolean
Dim freq As Currency, sc As Currency, ec As Currency
Dim dt As Double, i As Integer
'For about 50 sec
For i = 1 To 5
Loop Until (ec - sc) / freq >= 5
dt = (ec - sc) / freq
'Sanity check -- generous tolerance
If dt < 4.9 Or 5.1 < dt Then Exit For
'Last sleep duration
MsgBox Format(dt * 1000, "0.000 msec")
----- original message -----
"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote in message
It happens because VBA is working hard and gives no chance to update the
Put some DoEvents in.
Sleep won't help, maybe you can use Application.OnTime instead.
"Joe User" <joeu2004> wrote in message
I am using WinXP SP3 and Excel 2003 SP3 with VBA 6.5.
I have a long-running macro that is CPU-intensive. However, about every
1 sec, I log some information and sleep for 20 msec.
After "a while" (it varies), one or more open windows go blank. That is,
there is nothing but white inside the window frame. Moreover, my VBA
window is no longer the active window -- none is.
When I log to the Immediate Window, that window goes blank very soon,
often as soon as one page is filled (i.e. the window scrolls).
But this also happens when I log to a file -- and this time, it happened
to all windows, foreground and background. (I had walked away from the
computer for about 45 min.)
The system is still responsive. When I "break" and end the macro,
everything is usually restored to normal. But it is still disconcerting.
Any idea why that happens? Any idea how I can avoid it?
I suspect this is really a WinXP issue. Any idea what NG would be
monitored by responsive people who are knowledgable in this area (the
I've tried posting such technical questions to m.p.windowsxp.general in
the past. The response are usually not impressive.
I have extensive O/S background, albeit not with MS Windows. 20 msec is
usually at least two "ticks" (about 33 msec on WinXP). That is usually
plenty of time to run other non-CPU-intensive processes, e.g. for window
updates and timer-based bookkeeping.
Nonetheless, in other circumstances, I have extended the sleep to as much
as 1 sec, to no avail.
- Re: Why do windows go blank?
- From: RB Smissaert
- Re: Why do windows go blank?