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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to