• 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: Really Big Windows and Interrupting computations?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Really Big Windows and Interrupting computations?


  • Subject: Re: Really Big Windows and Interrupting computations?
  • From: Paul Collins <email@hidden>
  • Date: Tue, 22 Jun 2004 17:23:04 -0700

Threads are great, but I don't think you need them for this...

If you want to do a long computation that can be interrupted, one way is to use an NSTimer. By setting an NSTimer to fire after a short time and then returning from the current method, you are assured that the run loop will go through any inputs (for example, your Quit message).

You'll have to factor your computation into a method that is called repeatedly (by the NSTimer) and does one short chunk of the work at a time. Save the state after each chunk in instance variables that the method checks each time it starts up.

In your quit method, invalidate the timer (also invalidate it in -dealloc so you don't get the timer calling your class after it's gone!).

By the way, it's tempting to use the "repeats" version of NSTimer, but I've found it's rather troublesome in terms of getting your program logic right. Instead, just create a brand new NSTimer at the end of your special repeating method (and put it in an instance variable so the quit method can find it and invalidate it).

Also, NSRunLoop performSelector:target:argument:order:modes: can be handy in a similar way.

--Paul Collins

P.S. Looking at your web site, I fear I've put in a lot of things you already know, but too late now--anybody who's figured out the Power Manager and Security Manager probably doesn't need advice from me :-)

On Jun 22, 2004, at 1:16 PM, Jerry LeVan wrote:

I have a tight loop that looks like

put up a progress window
quit=NO
for i = 1 to some (possibly) big number
a(i) = some (upto )several second computation ( scaling big images )
force update of progress window with "displayIfNeeded"
if (quit) break
end


** Now in Public beta! http://www.opendoor.com/envision/ **
** Envision: a new way to experience the web **
** Gracion Software http://www.gracion.com/ **
** Tel: +1 (541) 488-3488 iChat/AV/AIM: gracionsoft **
** DigiTunnel 1.3 PPTP/VPN client for OS X **
_______________________________________________
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: 
 >Really Big Windows and Interrupting computations? (From: Jerry LeVan <email@hidden>)

  • Prev by Date: Re: TIFF Error?
  • Next by Date: Black Background in an imageview?
  • Previous by thread: Really Big Windows and Interrupting computations?
  • Next by thread: Re: Really Big Windows and Interrupting computations?
  • Index(es):
    • Date
    • Thread