• 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: To thread or not to thread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: To thread or not to thread?


  • Subject: Re: To thread or not to thread?
  • From: Andrew Thompson <email@hidden>
  • Date: Mon, 30 Jan 2006 10:51:45 -0800


On Jan 30, 2006, at 1:05 AM, Dado Colussi wrote:

Jeremy Hubbell wrote:
I have a simple function that randomly generates color values that I'd like to execute when a checkbox is enabled and terminates when the checkbox is unchecked. I tried a while loop using [sender state == 1]


Not to thread.

How about using an NSTimer to fire randomly? Set the first expiration time randomly and the interval to some long time. When the timer expires, it calls your handler function that does the color thing if the checkbox is checked and otherwise does nothing. Then readjust the next expiration time to a random time in the future at the end of your timer handler function.


I'm curious, why have it fire randomly?
My method would be to set the timer (with a .01 expiration time) when the checkbox is enabled, do one iteration of generating colors, then if the checkbox is still enabled, set the timer again with a .01 expiration time.
I'm not sure if this method is the best, but it seems simpler to me.


~Andrew

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: To thread or not to thread?
      • From: Dado Colussi <email@hidden>
References: 
 >To thread or not to thread? (From: Jeremy Hubbell <email@hidden>)
 >Re: To thread or not to thread? (From: Dado Colussi <email@hidden>)

  • Prev by Date: RE: How to prevent window redraw when removing a view?
  • Next by Date: Re: I think I have found a big bug in NSBrowser
  • Previous by thread: Re: To thread or not to thread?
  • Next by thread: Re: To thread or not to thread?
  • Index(es):
    • Date
    • Thread