Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wesg

macrumors regular
Original poster
Jan 2, 2008
211
0
Toronto, ON
I'm writing a Cocoa Obj-C application that has a single operation. It will work through a loop (for or while) in a single window.

I've gotten the interface working, but I'm stuck as to how best to implement a "cancel operation" button. What sort of code would I need to cancel the method that is started by the "DO work" button? Is there a single cancel operation that I can implement?
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
That would only work if you're doing the work on a background thread, since it'll never receive the cancel event if you're blocking the UI. If you aren't threading, you'd probably want to divide the work into bite-sized chunks and set a 0 delay timer to execute the next chunk each time one finishes so that the runloop has a chance to process events. Or use NSOperationQueue (which is equivalent to the background thread idea, but maybe easier to manage).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.