Re: Idle Time in a loop
Re: Idle Time in a loop
- Subject: Re: Idle Time in a loop
- From: Judi Smith <email@hidden>
- Date: Mon, 18 Feb 2002 22:46:44 -0600
Ben:
Now I see what you are saying! So I would use a timer or the like to
call my little method that needs to be performed repeatedly. That makes
perfect sense now.
Thanks for taking the time to explain.
JS
On Monday, February 18, 2002, at 10:46 PM, email@hidden wrote:
What I am trying to do here is give the interface time to run - you
know process button clicks and the like. I've tried doing running the
loop myself, but that definitely doesn't seem to work. The events are
not processed as you would expect.
The problem is that I need the whole interface - so I can't just pick
particular selectors.
I usually do this with a method similar to this (it has some problems
of
course but should get you started).
- (void)updateRunLoop
{
id event;
// post events
while (event = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode
dequeue:YES]) {
[NSApp sendEvent:event];
}
return;
}
Call it during idleTimes in your run loop ...
Eric's code here presumably works, although you'd have to be careful
with various re-entrancy issues and such. If the operation you're
doing was invoked by a menu item being chosen, for example, or a button
being pushed, AppKit might be expecting you to finish that action and
return to the top of the run loop before re-entering the AppKit. This
approach might work, but I would not be surprised if it had problems.
(Eric, I'm curious; how much have you used this technique, and what
problems have you had with it?)
What I was suggesting was rather different. I was suggesting letting
the run loop run as normal, and doing your ongoing task in the
background in a "worker" method that would get called repeatedly until
it was done, doing work for only a brief period before returning to the
run loop to allow new events to be processed. I think you read my
message as suggesting that running the interface would be done in that
"worker" method. Nope. The interface would be done by the top-level
run loop of the main thread, as usual. Your task would be what would
be getting done in the "worker" method. And since this way of doing
things lets AppKit work 100% as normal, it should have no issues due to
the Kit being "surprised" by what you're doing.
Try reading what I wrote earlier again, with this in mind. I think
you read it sort of upside-down. :-> I'll refrain from re-posting it
in this message; it is presumably in the archives for this list...
Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.