On Feb 17, 2007, at 1:12 AM, Jeffrey Ellis wrote:
I have the following code in a thread. All it's supposed
to do is display the current date/time, and continually update as a
clock.
While val(Format(d.totalseconds,
"##########"))<val(Format(theDate.totalseconds, "##########"))
d=new date
window1.currenttime.text=d.shortdate+" "+d.longtime
Wend
When run, I see this little app is hogging a major chunk of CPU.
It's at
nearly 50% of CPU on average, 17.1 MB of real ram, and more than
120 MB of
VM!
Why are you using a thread? Wouldn't a timer work better? I'd just
set a timer to fire every second. It may miss occasionally (timers
are not guaranteed time), but that's usually harmless with a clock
display. It seems to me the thread would be executing the above code
multiple times a second when the code only needs to be checked once a
second.
Also, you're doing extra work in the code above. Why use the Format
function to compare the totalSeconds values? Just compare the
integers themselves.
I use a timer approach for a clock display in one of my apps and it
doesn't use much CPU time at all.
Marc Zeedar
Publisher, REALbasic Developer magazine
www.rbdeveloper.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>