Hi, All,

In my app I have a timer, created in the awakeFromNib and living until the app terminates. And I have some problem when I close the application. Here are my code snippets:

- (void) awakeFromNib {
.......
        processingTimer = YES;
        timer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                                                
         target:self
                                                                                
   selector:@selector(onTimer:)
                                                                                
   userInfo:nil
                                                                                
        repeats:YES];
...
}

As I believe, everything is OK here...

- (void) dealloc {
        processingTimer = NO;
        [timer invalidate];
......
}

I'm not sure, if I must invalidate the timer, but think I should do it.

- (void)onTimer:(NSTimer*)timer {
.......
        //
        if (!processingTimer) return;
        //
< some procedure is going here, which updates the data for NSTableView
        //
        if (!processingTimer) return;
        //
        // Update results list in the NSTableView
        [fileView reloadData];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
here we had an exception within obc_msg_send()
........
}

Here is the onTimer: procedure, where I had an exception after I closed the application. I tried to remove timer invalidation from the dealloc, but nothing helped unless I've inserted a boolean var processingTimer, which should indicate whether our app still lives or it is slosing now. First I've added this var check only at the top of onTimer procedure, yet before the main calculating procedure call. That didn't helped. Then I've added yet another check right before the call of [NSTable reloadData]. And this helped. At least I've tried to run and close my app several times and I didn't see an exception.

Also I tried to change timer interval, believing that my main procedure runs too slowly, so overlapped onTimer calls occur. But it makes no sense.

So, what is the _correct_ way to do all that?

Thanks.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to