0

hey I have a task in which I need to perform a selector in background thread in which I need to do some video encodeing. The task goes fine. But if I press the back back button then I want that the method should be stop/kill. But it does not stop.

I searched a lot but does not found a satisfactory answere. I tried "cancellAllPreviousRequests" and also looked for NSQueueOperation but could not found how to use it to stop the background selector. Can anybody help me with relevent code.

Thank you in advance.

  • 1
    hi Have you tried like this [NSObject cancelPreviousPerformRequestsWithTarget:yourTarget selector:aSelector object: anArgument]; – 08442 Feb 13 '13 at 04:39
  • ya I am using this code but this does not work in my case [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(createFrameForVideo) object:nil]; –  Feb 13 '13 at 07:53

1 Answers1

1

You need a concurrent NSOperation which periodically checks if it has been cancelled, via its isCancelled property. You can then call the cancel method of the NSOperation or the cancelAllOperations of the NSOperationsQueue to stop the background task. Keep in mind, calling cancel does not actually stop the operation, but rather sets a boolean property that the operation should be periodically checking to see if it should kill itself (stop doing what it is doing). How often you check for the isCancelled flag inside your operation code is up to you.

For further reading see here and here.

Community
  • 1
  • 1
Joel
  • 15,654
  • 5
  • 37
  • 60