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

  • Home
  • SEARCH
  • 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 9201261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:57:47+00:00 2026-06-17T22:57:47+00:00

-(void)viewDidLoad{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(action_Timer) userInfo:nil repeats:YES]; } ); } -(void)action_Timer{

  • 0
-(void)viewDidLoad{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [NSTimer scheduledTimerWithTimeInterval:0.10 
                                         target:self 
                                       selector:@selector(action_Timer) 
                                       userInfo:nil 
                                        repeats:YES];
        }
    );
}

-(void)action_Timer{
    LOG("Timer called");
}

action_Timer is not being called. I dont know why. Do you have any idea?

  • 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-17T22:57:49+00:00Added an answer on June 17, 2026 at 10:57 pm

    You’re calling +[NSTimer scheduledTimerWithTimeInterval:...] from a GCD worker thread. GCD worker threads don’t run a run loop. That’s why your first try didn’t work.

    When you tried [[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode], you were sending a message to the main run loop from a GCD worker thread. The problem there is NSRunLoop is not thread-safe. (This is documented in the NSRunLoop Class Reference.)

    Instead, you need to dispatch back to the main queue so that when you send the addTimer:... message to the main run loop, it’s done on the main thread.

    -(void)viewDidLoad {
        [super viewDidLoad];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSTimer *timer = [NSTimer timerWithTimeInterval:0.10 
                                             target:self 
                                           selector:@selector(action_Timer) 
                                           userInfo:nil 
                                            repeats:YES];
            dispatch_async(dispatch_get_main_queue(), ^{
                [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
            });        
        });
    }
    

    Realistically, there’s no reason to create the timer on the background queue if you’re going to schedule it in the main run loop. You can just dispatch back to the main queue to create and schedule it:

    -(void)viewDidLoad {
        [super viewDidLoad];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSLog(@"on background queue");
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"on main queue");
                [NSTimer scheduledTimerWithTimeInterval:0.10 
                                             target:self 
                                           selector:@selector(action_Timer) 
                                           userInfo:nil 
                                            repeats:YES];
            });        
        });
    }
    

    Note that both of my solutions add the timer to the main run loop, so the timer’s action will run on the main thread. If you want the timer’s action to run on a background queue, you should dispatch to it from the action:

    -(void)action_Timer {
        // This is called on the main queue, so dispatch to a background queue.
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            LOG("Timer called");
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

- (void)viewDidLoad { moveObjectTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(moveObject) userInfo:nil repeats:YES] -(void)moveObject image.center =
- (void)viewDidLoad { UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)]; tapGesture.numberOfTapsRequired = 1; tapGesture.numberOfTouchesRequired
- (void)viewDidLoad { [super ViewDidLoad]; [brandTextField addTarget:self action:@selector(showImageFromFilter) forControlEvents:UIControlEventAllEvents]; } - (void)showImageFromFilter { if
I'm trying to observe changes to an NSMutableString isDetailView : -(void)viewDidLoad { [self addObserver:self
- (void)viewDidLoad { graph = [[CPTXYGraph alloc] initWithFrame: self.view.bounds]; CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
- (void)viewDidLoad { [super viewDidLoad]; self.carMakes = [[NSArray alloc] initWithObjects:@Chevy, @BMW, @Toyota, @Volvo, @Smart,
- (void)viewDidLoad { [super viewDidLoad]; definedNames = [[NSArray alloc] initWithObjects:@Ohio, @Newark, @Steve, @Coffee, nil];
.m coding: -(void)viewDidLoad { NSString *path = [[NSBundle mainBundle] pathForResource:@MathMusic2 ofType:@wav]; self.theAudio = [[AVAudioPlayer
- (void)viewDidLoad{ UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; [self.view addSubview:baseView]; //
Here is my code: - (void)viewDidLoad{ [super viewDidLoad]; self.authorList = [[NSArray alloc] initWithObjects:@Christie, Agatha,

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.