• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Idle Time in a loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Idle Time in a loop


  • Subject: Re: Idle Time in a loop
  • From: Judi Smith <email@hidden>
  • Date: Mon, 18 Feb 2002 20:41:35 -0600

Eric:

You are the MAN!! That did the trick and does exactly what I want it to do.
Simple and straightforward. Thanks so much!

JS

On Monday, February 18, 2002, at 08:23 PM, Eric Peyton wrote:

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

On Monday, February 18, 2002, at 07:37 PM, Judi Smith wrote:

Ben:

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.

Any clues?

Judi


On Monday, February 18, 2002, at 01:14 PM, email@hidden wrote:

I have a while loop that is performing a task. How do I allow for time for, or transfer control to the event loop to process pending events in the course of the while loop?

It's truly quite easy: you don't. Instead you move your while loop into a separate thread.

Well, that's one solution. However, it is often much less complex to avoid the issues multithreading raises, and just return to the top of the run loop periodically. There's nothing wrong with that, for many tasks. Basically, request periodic events in some way (you could use an NSTimer, or schedule performs for yourself using -performSelector:...afterDelay:..., or schedule performs for yourself in the run loop using the API in NSRunLoop.h, or use NSEvent's +startPeriodicEvents... API, or use delayed notifications, or probably some other ways as well; it depends on exactly how and when you want your code to run). Each time that you get time from the run loop, do a little work and then return. Segment your task in such a way that you remember the work you've already done, and pick up each time where you left off the previous time.
Background layout of text in AppKit, for example, is done using delayed notifications set to run when the app is idle. This can be a better model than using threads, for various reasons.
You could also conceivably run the run loop yourself; see the doc on -[NSRunLoop run] and other methods. However, as I understand it, this is generally a very bad idea, although I don't know NSRunLoop well enough to know why. Can anybody else fill this out?

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.
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Re: Idle Time in a loop (From: Eric Peyton <email@hidden>)

  • Prev by Date: Authorization API calI in Cocoa-Java
  • Next by Date: Re: iDisk access in Cocoa
  • Previous by thread: Re: Idle Time in a loop
  • Next by thread: Re: Idle Time in a loop
  • Index(es):
    • Date
    • Thread