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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:38:09+00:00 2026-06-12T02:38:09+00:00

xCode 4.4.1 OSX 10.8.2, looks like [operation cancelAllOperations]; isn’t working – (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

  • 0

xCode 4.4.1 OSX 10.8.2, looks like [operation cancelAllOperations]; isn’t working

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSOperationQueue *operation = [[NSOperationQueue alloc] init];
    [operation setMaxConcurrentOperationCount: 1];
    [operation addOperationWithBlock: ^{
        for (unsigned i=0; i < 10000000; i++) {
            printf("%i\n",i);
           }
    }];
    sleep(1);
    if ([operation operationCount] > 0) {
        [operation cancelAllOperations];
    }
}

results 9999999

  • 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-12T02:38:10+00:00Added an answer on June 12, 2026 at 2:38 am

    Inside your block, particularly inside the loop, call -isCancelled on the operation. If it’s true, then return.

    NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
    [operationQueue setMaxConcurrentOperationCount: 1];
    
    NSBlockOperation *operation = [[NSBlockOperation alloc] init];
    __weak NSBlockOperation *weakOperation = operation;
    [operation addExecutionBlock: ^ {
        for (unsigned i=0; i < 10000000; i++) {
            if ([weakOperation isCancelled]) return;
            printf("%i\n",i);
        }
    }];
    [operationQueue addOperation:operation];
    
    sleep(1);
    
    if ([operationQueue operationCount] > 0) {
        [operationQueue cancelAllOperations];
    }
    

    A queue can’t just stop the operation’s execution arbitrarily – what if some shared resources were being used by the operation that never got cleaned up? It’s your responsibility to orderly end the operation when it becomes known to be cancelled. From Apple’s docs:

    An operation object is responsible for calling isCancelled
    periodically and stopping itself if the method returns YES.

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

Sidebar

Related Questions

xcode 4.5 OSX 10.8 CoreLibrary(529mb) install error like this. Failed to install documentation for
I'm working on an OSX application (using xcode) and all the versionning stuff is
OSX 10.7, XCode 4. I have a small problem: I need to push back
I've recently updated xcode to 4.3.3 with osx sdk 10.7.4 in it. After that
I am new to Mac OSX, and I wonder if Xcode can generate ,
So I have some Objective-c code that was created in Xcode 3.1 on OSX
I noticed when I run Xcode especially start to run Interface builder. Mac osx
xcode 4.2 os x 10.7 when i set my includes to look like: #include
I am trying to add the Parsekit framework to my OSX Xcode project. I've
On OSX 10.6.4 with iPhone SDK and Xcode 3.2.1 installed: $ gcc foo.c -arch

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.