Re: NSMatrix mouse puzzle
Re: NSMatrix mouse puzzle
- Subject: Re: NSMatrix mouse puzzle
- From: "D.K. Johnston" <email@hidden>
- Date: Wed, 3 Sep 2008 23:14:38 -0700
Thanks for your reply. The "index" variable is actually "i": I forgot
to change it when pasting the code into the email. So it does
terminate after 10 seconds.
The reason I want a delay is that the user is supposed to have 10
seconds only to look at the data displayed in the matrix. Then it's
cleared. (It's a memory test, to prevent drunks from starting a
computer.)
I was looking at NSTimer, but it seemed simpler to do what I did. I'll
look again.
dkj
P.S. And indeed, I'm not a real programmer: I just play one on TV.
On 3 Sep, 2008, at 21:52, Graham Cox wrote:
On 4 Sep 2008, at 2:40 pm, D.K. Johnston wrote:
// wait 10 seconds
NSUInteger i = 0, resume = time( nil ) + 10;
while( i < resume )
index = time( nil );
Don't do this!
This is not a good way to wait for a period of time, even if waiting
for a period of time were a good way to do what you want (which it
isn't). All this does is chew up CPU time - events will still be
captured and queued while this is running, so when it ends, they
just get processed and passed to the now enabled control. Also, as
posted the above code never terminates - i is never changed.
What's to say your "data display" always takes 10 seconds anyway?
Depends on the data, the machine you're running on, etc, etc... time
delay loops are what a first-timer using BASIC uses - real
programmers never do this.
Disable the matrix at the start of data load. When the data load
finishes, signal that fact to some object that re-enables the
control. Load the data asynchronously (using a thread or timer-
driven loop).
hth,
Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden