Print Page | Close Window

Coroutine.Cancel() and Custom Operations

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3514
Printed Date: 25-Mar-2025 at 4:09pm


Topic: Coroutine.Cancel() and Custom Operations
Posted By: ken.nelson
Subject: Coroutine.Cancel() and Custom Operations
Date Posted: 03-Jul-2012 at 1:34pm

I'm wondering what the Coroutine.Cancel method is doing under the hood. The Remarks section states that all operations which haven't yet completed will be cancelled. The reason I'm asking is because we've written our own Operations that implement the INotifyCompleted interface. These operations allow us to call our custom web-service methods inside a Coroutine, but since INotifyCompleted doesn't define Cancel(), I'm wondering how Coroutine.Cancel() would know how to cancel it.

 

Really I guess the bottom-line question is: What do we have to do to make sure our custom Operations are properly cancelled when used inside a Coroutine and Coroutine.Cancel is called?

 

 

// Summary:

//     Cancel a currently running coroutine.

//

// Parameters:

//   coroutineOperation:

//

// Remarks:

//     If the iterator is still running, cancels all operations which haven't yet

//     completed.

public static void Cancel(CoroutineOperation coroutineOperation);




Replies:
Posted By: kimj
Date Posted: 03-Jul-2012 at 2:01pm
If a Coroutine operation inherits from BaseOperation the Cancel request will also try to cancel that operation.
 
One thing to note though, is that a web service request might not be truly cancellable anyway.  This is the case for the async requests to the EntityServer - the underlying service operations cannot be cancelled, but we do stop tracking them when cancel is requested.


Posted By: ken.nelson
Date Posted: 05-Jul-2012 at 6:57am
Yeah that's what I was concerned about. We don't inherit from BaseOperation, just INotifyCompleted, so even though we have a Cancel() method and a Cancelled property, they'll never be called.
 
We might be in the same boat with respect to web services, but at the very least I'd like to abort the client, unwire event-handlers and close it down properly.
 



Print Page | Close Window