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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:25:35+00:00 2026-05-27T22:25:35+00:00

I have an application in which I am repetitively calling a method in background.

  • 0

I have an application in which I am repetitively calling a method in background. I implemented this by following below steps:

  1. created a background thread,
  2. called the appropriate method on the created thread,
  3. called sleep method on the thread, and
  4. again called the previously invoked method.

Below is the code which I used:

- (void) applicationDidFinishLaunching:(NSNotification *)notification
    [NSApplication detachDrawingThread:@selector(refreshUserIdPassword) toTarget:self withObject:nil];
}

-(void)refreshUserIdPassword
{
    [self getAllUserIdsPasswordsContinousely];
    [NSThread sleepForTimeInterval:180];
    [self refreshUserIdPassword];

}

I have read that NSThread is not the best way to perform background task, and there are other classes provided in cocoa, such as – NSOperationQueue and GCD, which should be preferred over NSThread to perform an asynchronous task. So I am trying to implement the above specified functionality using the alternative classes.

Problem is – though I am able to perform an asynchronous task using
these classes, I am unable to perform a repetitive task (as in my
case) using these classes
.

Can someone throw some light on this and guide me towards the correct direction?

  • 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-27T22:25:35+00:00Added an answer on May 27, 2026 at 10:25 pm

    I think you’ll get a stack overflow (no pun intended) using the code you’ve posted. -refreshUserIdPassword recurses infinitely…

    How about using GCD?

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        // Insert code here to initialize your application
        dispatch_source_t timerSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
        dispatch_source_set_timer(timerSource, dispatch_time(DISPATCH_TIME_NOW, 0), 180*NSEC_PER_SEC, 10*NSEC_PER_SEC);
        dispatch_source_set_event_handler(timerSource, ^{
            [self getAllUserIdsPasswordsContinuously];
        });
        dispatch_resume(timerSource);
        self.timer = timerSource;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have application in which i have a web server api .this is my
I have application which loads images like this: someImage = Image.FromFile(@picture.png); and another application
I have application which can export slides to PowerPoint. I'm using Microsoft.Office.Interop.PowerPoint.dll . This
I have application which consumes XML and based on this creates a GUI. Basically
I have an application which needs to encrypt and decrypt strings. Below is my
I have application which runs in background. I have some problem - my application
I have application which needs to use a dll (also written by me) which
I have an application which really should be installed, but does work fine when
I have an application which extracts data from an XML file using XPath. If
We have an application which needs to use Direct3D. Specifically, it needs at least

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.