• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to cancel an NSInvocationOperation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to cancel an NSInvocationOperation


  • Subject: Re: How to cancel an NSInvocationOperation
  • From: Mike Abdullah <email@hidden>
  • Date: Mon, 16 Apr 2012 11:38:45 +0100

On 16 Apr 2012, at 10:07, Gerriet M. Denkmann wrote:

> I have this code:
>
> NSMethodSignature *ms = [ self methodSignatureForSelector: @selector(someMethod:) ];
> NSInvocation *inv = [NSInvocation invocationWithMethodSignature: ms ];
> [ inv retainArguments ];
> [ inv setSelector: @selector(someMethod:) ];
> [ inv setTarget: self ];
> [ inv setArgument: &a atIndex: 2 ];
>
> NSInvocationOperation *ivo = [ [ NSInvocationOperation alloc ] initWithInvocation: inv ];
> [ self.operationQueue  addOperation: ivo ];
>
> Works fine. But the documentation says: "An operation object is responsible for calling [isCanceled] periodically and stopping itself if the method returns YES."
>
> But how do I check for "isCanceled" from within someMethod: ?
>
> Is there something like: +[ NSOperation theOperationThisCodeIsRunningIn ]?
>
> I tried (inside of someMethod:):
> NSThread *currentThread = [ NSThread currentThread ];
> if ( [ currentThread isCancelled ] ) NSLog(@"%s Cancelled",__FUNCTION__);
>
> But this has no effect.

I'm not surprised! Cancelling an operation certainly does not cancel the thread it's running on!

If you want your operation to be properly cancellable while running, it's time to subclass NSOperation, rather than use NSInvocationOperation.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How to cancel an NSInvocationOperation (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Fast Enumeration and temporary objects/autoreleasing
  • Next by Date: Re: When to declare variables and the compiler's intelligence
  • Previous by thread: How to cancel an NSInvocationOperation
  • Next by thread: Fast Enumeration and temporary objects/autoreleasing
  • Index(es):
    • Date
    • Thread