• 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: Notifications instead of a Timer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notifications instead of a Timer


  • Subject: Re: Notifications instead of a Timer
  • From: Brant Vasilieff <email@hidden>
  • Date: Fri, 14 Mar 2003 13:39:06 -0800

Yes you can.

Avoid polling when ever possible. If "updateTheThing" is not just refreshing the screen, you could place it in another thread, and use a lock to start/stop it.

Ideally, you want your application consuming zero time when it's waiting.

Somewhere in your code you change "thisThing", after that's over, you could then send a notification that it has been updated.

If it's something that gets changed frequently, and you don't need to respond to each change, then a timer used as a delay device works well. But rather than start a repeating timer, you invalidate the existing timer, and create a new one. As an example, if you wanted to implement a filter field like that found in Mail and wanted to change the listed items when the user changed the contents of the field, you could use a timer. Each time the user hits a key or causes the text to change, you invalidate any old timer and then create a new timer to fire in half a second. As long as the user is still making changes to the field, the trigger date will constantly get pushed out into the future. When they stop typing, then one and only one timer is fired notifying you to update the list of items.

HTH,
Brant

On Friday, March 14, 2003, at 12:07 PM, email@hidden wrote:

Hi,

Correct me if I'm wrong, but can you replace a timer by simply using
Notifications? For example, when something happens I need to take a
certain action, and current I use this method from a timer:

(pseudo code)

- (void)refresh:(id)sender {
if ([self thisThingChanged] || [self thisOtherThingChanged]) {
[self updateTheThing];
}
}

I was thinking that perhaps notifing the object about the changes that
it would be better, and more CPU friendly :)
_______________________________________________
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.

  • Prev by Date: Re: NSAppleEventManager details ??
  • Next by Date: Saving data to a file
  • Previous by thread: Notifications instead of a Timer
  • Next by thread: Menu Item "Close" stopped working
  • Index(es):
    • Date
    • Thread