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

The Archive Base Latest Questions

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

I am using NSThread along with NSTimer. My code is like this -(void) checkForRecentAlarm

  • 0

I am using NSThread along with NSTimer.

My code is like this

-(void) checkForRecentAlarm
{
    if ([self.alarmThread isFinished]) 
     {
        [self.alarmThread cancel];
     }
    self.alarmThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerForRecentAlarm) object:nil];
    [self.alarmThread start];
    //[NSThread detachNewThreadSelector:@selector(startTimerForRecentAlarm) toTarget:self withObject:nil];
}
-(void)startTimerForRecentAlarm
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
    self.recentAlarmTime = [NSDate date];
    self.dbObject = [[RADataBaseModelManager alloc] init];
    self.recentAlarmTime = [self.dbObject getMostRecentAlarmTimeFromDB];
    if (self.recentAlarmTime) {
        NSTimeInterval timeIntervalToAlarm = [self.recentAlarmTime timeIntervalSinceNow];
        NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
         //Fire timer every second to updated countdown and date/time
        self.RATimer = [NSTimer scheduledTimerWithTimeInterval:timeIntervalToAlarm target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:NO];
        [runLoop run];
    }
    [pool release];
}
 - (void)timerFireMethod:(NSTimer*)theTimer
{
    [self.RATimer invalidate];
    [theTimer invalidate];
    self.RATimer = NULL;
    theTimer = NULL;
    [self playAlarm];
    UIAlertView *alarmAlert = [[UIAlertView alloc] initWithTitle:@"Alarm" message:@"" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"Snooze", nil]; 
    [alarmAlert show];
    [alarmAlert release];
    alarmAlert = nil;

}

Now the problem is, my alertbox comes twice for one call in the
startTimerForRecentAlarm
method. So that the alert comes consequently twice and my view get stuck.

What will be problem here?

I am trying to implement an alarm with multiple alarm option using a single NSTimer.

Please help.

When I debug this, I can find many simultaneous threads are running on same code(UIAlertView).

  • 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-26T23:06:50+00:00Added an answer on May 26, 2026 at 11:06 pm

    I can’t see any obvious reason why that would be called twice, but it does seem like an overly complex way of doing what you need to do.

    Have you thought about using local notifications?

    If you don’t want to do that, you could refactor your code so it works like this:
    1. Add a new event
    2. If there’s no timer or the time to the event is shorter than the time on the timer, then set the timer for this event.
    3. When a timer fires, check for the next event and set a timer for that event (if there is one).

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

Sidebar

Related Questions

i m using this on uitableviewcell's didselectrow method [NSThread detachNewThreadSelector:@selector(showMyWaitView) toTarget:self withObject:nil]; it works
I' m calling doSaveItems: like [NSThread detachNewThreadSelector:@selector(doSaveItems:) toTarget:self withObject:aObject]; doSaveItems: method has a code
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Currently I'm using NSThread to cache images in another thread. [NSThread detachNewThreadSelector:@selector(cacheImage:) toTarget:self withObject:image];
I created a sub-thread using NSThread in main thread NSThread *newThread = [[NSThread alloc]
I'm successfully making a ASIFormDataRequest using the below code. //get groups if (![self queue])
I am passing an object to a secondary thread using the following code: (void)login:(id)sender
Possible Duplicate: NSTimer doesn't stop I am using [NSThread exit] to leave the NSTimer
I am using NSThread to create new thread that displays images in my application.
I have to perform a timer using a NSThread as I need to download

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.