Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4596392
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:06:29+00:00 2026-05-21T23:06:29+00:00

I’ll go straight to the problem. This ones eating my head since a week.

  • 0

I’ll go straight to the problem.

This ones eating my head since a week.

What i intend to do is set my timer, which is supposed to be fired on main run loop, from a secondary thread. So i do it as follows.

if(timerRefresh)
{
    //[timerRefresh invalidate];
    timerRefresh = nil;
}

if (!self.isConnectionAvailable) {
    timerRefresh = [NSTimer timerWithTimeInterval:appDelegate.TimerInterval target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
}
else if (self.isLivePresent||self.isUpcomingMatchToday) {
    timerRefresh = [NSTimer timerWithTimeInterval:appDelegate.TimerInterval target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
}
else {
    timerRefresh = [NSTimer timerWithTimeInterval:LongRefresh target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
}

NSRunLoop *runLoop = [NSRunLoop mainRunLoop];
[runLoop addTimer:timerRefresh forMode:NSDefaultRunLoopMode];
[runLoop run];

When this fires, a loader begins loading on the main thread, and the processing work is done on the secondary thread.

I hope this is a correct way.

Now i have a child class within this main class which also has to show a loader while it triggers a filtering process, so to avoid multiple loaders, when the the filtering process triggers, i pause the refreshing on this parent class, by sending it notifications from the child class..like this…

-(void)teamNameClicked:(id)sender
{
    BOOL result = YES;
    NSNumber *newNumber = [NSNumber numberWithBool:result];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"PauseMatchesLiveMatchTimer" object:newNumber];

    [self performSelector:@selector(sendTeamNameClickToFunction:) withObject:sender];
}

and when operation completes i have another notifier as this…

-(void)processTeamNameClick:(id)sender
{
    UIButton *button = (UIButton *)sender;
    selectedIndexDropDown  = button.tag;

    [self parseTeamFile:button.tag];
    self.lblDropDown.text = [dictTeamFilter valueForKey:[NSString stringWithFormat:@"%i",button.tag]];
    [tblResults performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

    BOOL result = NO;
    NSNumber *newNumber = [NSNumber numberWithBool:result];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"PauseMatchesLiveMatchTimer" object:newNumber];
}

Notice the YES and NO for results..

Now this is an observer for the notification…

-(void)pauseAndResumeTimer:(NSNotification *)notification;
{
    NSNumber *newNumber = [notification object];
    BOOL result = [newNumber boolValue];

    if (result) {
        if(timerRefresh)
        {
            if ([timerRefresh isValid])
                [timerRefresh invalidate];
            timerRefresh = nil;
        }
    }
    else 
    {
        if(timerRefresh)
        {
            if ([timerRefresh isValid])
                [timerRefresh invalidate];
            timerRefresh = nil;
        }

        if (!self.isConnectionAvailable) {
            timerRefresh = [NSTimer timerWithTimeInterval:appDelegate.TimerInterval target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
        }
        else if (self.isLivePresent||self.isUpcomingMatchToday) {
            timerRefresh = [NSTimer timerWithTimeInterval:appDelegate.TimerInterval target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
        }
        else {
            timerRefresh = [NSTimer timerWithTimeInterval:LongRefresh target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
        }

        NSRunLoop *runLoop = [NSRunLoop mainRunLoop];
        [runLoop addTimer:timerRefresh forMode:NSDefaultRunLoopMode];
        [runLoop run];
    }
}

When the filtering process is on, i stop the parent timer. And when off i start it again.

Ok…So now the problem… When i do normal navigation on my pages, it works absolutely fine..like switching tabs, traversing between pages etc.

But if i use the filter process, somehow, it triggers my timer on the main page, and even when the view has disappeared, seems to kick off my timer event. I want to avoid that, but i just dont know how..

If anyone can genuinely help me, please do.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:06:30+00:00Added an answer on May 21, 2026 at 11:06 pm

    There is some funny stuff going on in your code:

    • First and formemost, I am at least least 90% positively sure that you don’t want to call [[NSRunLoop mainRunLoop] run] in any of your program’s methods — do those methods even exit, or do you keep aggregating thread upon thread?
    • Secondly, your timer invalidations are all a bit strange:
      1. There is no use in if (timerRefresh) if ([timerRefresh isValid]) [timerRefresh invalidate];; since in Objective C, messaging nil is perfectly fine. The result of such a message is always 0x0, so the first if is unnecessary and the second one evaluates to NO in that case, anyway.
      2. Invalidating a timer means removing it from the runloop it was scheduled on. Hence, the second if is unnecessary, too — leaving you with just [timerRefresh invalidate];.
      3. For -[NSTimer invalidate] to have an effect, it needs to be called on the thread the timer is scheduled on. From what I understood, this is not the case in all your methods. So you should use performSelectorOnMainThread:withObject:waitUntilDone: with the appropriate arguments instead.
    • There is no difference between [self performSelector:@selector(sendTeamNameClickToFunction:) withObject:sender] and simply [self sendTeamNameClickToFunction:sender]. Except that the latter is much easier to read 😉
    • The if clauses in pauseAndResumeTimer: don’t make an awful lot of sense, i.e. there’s a lot of code duplication.

    Here is said method in a tidied-up fashion and with the invalidation happening on the main thread:

    -(void)pauseAndResumeTimer:(NSNotification *)notification
    {
        [timerRefresh performSelectorOnMainThread:@selector(invalidate) withObject:nil waitUntilDone:YES];
        timerRefresh = nil;
    
        NSNumber *result = [notification object];
        if ([result boolValue]) return;
    
        if ( !self.isConnectionAvailable || self.isLivePresent || self.isUpcomingMatchToday ) {
            timerRefresh = [NSTimer timerWithTimeInterval:appDelegate.TimerInterval target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
        } else {
            timerRefresh = [NSTimer timerWithTimeInterval:LongRefresh target:self selector:@selector(startAutoRefresh) userInfo:nil repeats:NO];
        }
    
        [[NSRunLoop mainRunLoop] addTimer:timerRefresh forMode:NSDefaultRunLoopMode];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.