1

NSOperation gets completed before background task are over

I am calling and NSOperation and have set max concurrent task 2 NSOperation calls some background methods but NSOperation does not wait for the background tasks to be completed  and get removed from the queue so next operation starts which I do not want Please help, how to let NSOperation continue till the background task gets completed.

Mani
  • 17,549
  • 13
  • 79
  • 100
Vibhooti
  • 1,193
  • 2
  • 9
  • 20
  • 1
    Can you show your code where you created the NSOperation object? If you use a subclass, it's crucial that you implemented it *correctly*. If you use the `addOperationWithBlock:` method taking a block as argument, your block must be executing *synchronous*. See also https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html – CouchDeveloper Dec 12 '13 at 08:45

2 Answers2

1

I hope you may get your answer here in

  1. Stackoverflow post.

  2. StackOverflow Discussion

Community
  • 1
  • 1
Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41
1

NSOperation KVO's it's properties isFinished and isExecuting. From documentation

Upon completion or cancellation of its task, your concurrent operation object must generate KVO notifications for both the isExecuting and isFinished key paths to mark the final change of state for your operation. (In the case of cancellation, it is still important to update the isFinished key path, even if the operation did not completely finish its task. Queued operations must report that they are finished before they can be removed from a queue.) In addition to generating KVO notifications, your overrides of the isExecuting and isFinished methods should also continue to return accurate values based on the state of your operation.

Basically when you generate a notification isFinished = YES and isExecuting = NO, your NSOperation will be removed from the queue.

Community
  • 1
  • 1
Marko Hlebar
  • 1,973
  • 17
  • 18