Sunday 15 August 2010

osx - Stop pinwheel of death in infinite loop Objective C -


I am writing a simple timer program in Objective-C for my Mac. The timer is counted properly, but I get death spinning pinwheel. How can I go to Pinwill? I think because of this I have an infinite loop, but there should be nothing to bypass it.

I have an IBAction, which is triggered on a button click (button starts). And from there, it calls another function that works.

This is my account:

  - (IBAction) timer start: (ID) sender {self.timerDidPause = no; [Self timerring]; }   

And there is a timerring:

  - (zero) timerring {for (;;) {sleep (1000000); If (self.timerDidPause == yes) {} else {if (self.seconds == 0) {if (self.minutes == 0) {[self timerDone]; break; } And {self .seconds = 59; Self .minutes = Self. Min - 1; [Self format timer label: Selfhours: self Minutes: Self. Second]; }} And {self .seconds = self.seconds - 1; [Self format timer label: Selfhours: self Minutes: Self. Second]; In this function, the function format TimerLabel is called here, so it is:  
  - (zero) format timer label: (integer ) Hours: (int) minutes: (int) seconds {NSString * minuteString = [[NSString alloc] init]; NSString * second string = [[NSString alloc] init]; If (minutes & lt; 10) {min string = [NSString stringWithFormat: @ "0% d", min]; } And {minstrings = [NSString stringWithformat: @ "% d", min]; } If (seconds and lieutenant; 10) {seconds string = [NSString stringWithFormat: @ "0% d", sec]; } Else {secondString = [NSString stringWithFormat: @ "% d", sec]; } [Self-Timer label setString value: [NSSTING stringWaterFormat: @ "% d:% @:% @", hours, minstrestring, secondstrings]]; [Self. Tiemer Label Display]; }   

You are creating the UI thread hanging with your loop. After a few seconds of that, the OS has switched the cursor to the piner.

You need to schedule a timer to run outside the UI thread.

No comments:

Post a Comment