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 8912877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:19:35+00:00 2026-06-15T04:19:35+00:00

When I use it like that the ns timer worksi.e its calling both foo1

  • 0

When I use it like that the ns timer worksi.e its calling both foo1 and foo1

-(void)register1
{
    NSRunLoop * runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(foo) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];
     [runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(foo2) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];
    [runLoop run];
}

but my requirement is I have to use nstimer in different functions so that I can create an nsoperation of both.The code below only calls the first function.i.e when I call both register1 and register2 from main only 1 timer is registered.the top one

-(void)register1
{
    NSRunLoop * runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(foo) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];

    [runLoop run];
}
-(void)register2
{

    NSRunLoop * runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(foo2) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];
    [runLoop run];
}

I have found an answer to my question,thought I should tell others too.The solution is I had to use different threads for each function.I used nsoperation in main in this way

abc *ab=[[abc alloc]init];
//[ab register1];
  //  [ab register2];


    NSOperationQueue *queue=[[NSOperationQueue alloc]init];
    NSInvocationOperation *abc=[[NSInvocationOperation alloc]initWithTarget:ab selector:@selector(register1) object:(nil)];
    NSInvocationOperation *abc2=[[NSInvocationOperation alloc]initWithTarget:ab selector:@selector(register2) object:(nil)];
   [queue addOperation:abc];
    [queue addOperation:abc2];
  • 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-06-15T04:19:37+00:00Added an answer on June 15, 2026 at 4:19 am
    1. Don’t call -[NSRunLoop addTimer:forMode:] when you’re using +[NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:] – it’s redundant. The scheduled part of the name says it all: it’s creating a timer that’s already scheduled on the current runloop for you.
    2. Don’t call -[NSRunLoop run], in general. It runs the runloop indefinitely. It basically never returns. So your second function isn’t actually being called, since you never return from your first one. You could confirm this trivially by inserting NSLog statements in various places, or stepping through your code in the debugger.

    If you post more of your code – particularly your main() function – then we can provide you further answers. Generally you want to call -[NSRunLoop run] (or variations thereof) only from main().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't want to submit projectname.project folder. Now, I use like that git add
I use Event log like that: if(!EventLog.SourceExists(Service)) EventLog.CreateEventSource(Service,Sending notification email error); EventLog.WriteEntry(Service, System.String.Format(Sending notification
I was wondering if there was anyway to use functions like ReadFileEx that require
I use a lot of lines like that Console.WriteLine(Test); to debug application under VS
I have a script like that genhash --use-ssl -s $IP -p 443 --url $URL
I use oracle 10. I have update statement like that : update table1 t1
I use Spring MVC [version: 2.5] and Security[version: 2.0.4]. My problem looks like that:
I use flask with flask-peewee and wtfpeewee. So, I have models like that: class
some pages that use macros like: topusers or popularlabels are really slow to load.
I need to use something like get_or_create() but the problem is that I have

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.