Aleydis


Hi,

I wonder if there is some out-of-the-box support in the WF for cancelling plain activities (i.e. directly derived from System.Workflow.ComponentModel.Activity class.)

The default implementation of the CompositeActivity manages the transition into Canceling and Faulting state, respectively. However, the default implementation of the base Activity's Cancel() method does (almost) nothing; no state transition, no events fired.

I have a scenario where I need to cancel a custom activity derived from the Activity class. My custom activity may be a workflow activity (i.e. directly under the root activity) or embedded in some other CompositeActivity. The command to cancel said activity comes from the outside world and contains just enough information to identify the activity instance itself.

At the moment I call this.Cancel() from inside my activity but no transition happens. I cannot set the ActivityExecutionStatus myself because this is the scheduler's job.

I know the recommended way of cancelling a composite activity is to call CancelActivity() for the children on the composite's AEC. Now how can I grab my activity's parent AEC at run-time to invoke CancelActivity() on it Is this the recommended way of doing the cancellation for plain activities (seems a bit contrieved to me) or am I missing some crucial point

I really need that StatusChanged notification Execution -> Canceling being fired for my activity :-)

Thanks,

Aleydis



Re: Recommended way of cancelling a non-composite activity

SonaliC


An activity can be canceled if it is in executing state.

Check this post http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=688104&SiteID=1

and this sample http://msdn2.microsoft.com/en-us/library/ms742169.aspx which explains how to cancel a workflow by enqueing an exception.

Let us know if this is useful






Re: Recommended way of cancelling a non-composite activity

Aleydis

Thanks for the reply, Sonali.

What I need is cancelling of a non-composite activity from inside that activity. I do not wish for the workflow instance to terminate/complete; one could say I wish actually to "skip" the activity (still better, I wish it to execute an alternative code - not the normal "execute" code - and I need to know via an event when this happens).

All samples/concepts I've seen so far deal with cancelling of a composite activity, where the composite actively initiates the canceling of its own children. One may define CancellationHandlers only for a composite activity.

My problem lies the other way round:

The child of a composite activity (or a "child" of the root activity) receives the command to "cancel" itself. I would like to perform alternative code and to have the activity transit into the canceling state + firing the StatusChange event.

If this is my workflow definition, the red activities should be the ones which may have to perform a "Cancel" command.

+ rootActivity

+ some activity

+ a composite activity

+ a child activity

+ my non-composite activity

+ another child activity

+ some other activity

+ my non-composite activity

+ yet another activity

I'd just like to know if there is some concept of canceling a non-composite activity from inside that activity (not via its parent) and getting the transitions + events right without much additional work.

Thanks again,

Aleydis






Re: Recommended way of cancelling a non-composite activity

Aleydis

Just another thought:

If the concept of canceling activities is build around "parent is responsible / initiates the canceling of its children" could I get the parent's AEC from inside the child activity

I've tried

childAEC.ExecutionContextManager.GetExecutionContext(this.Parent);

from inside the child but got a null context.

With a valid parent context I could trigger the scheduler to enqueue the cancel command for the child.

Aleydis





Re: Recommended way of cancelling a non-composite activity

SonaliC

Cancellation of an activity is always triggered by the parent activity. It is not possible for an activity to send a 'cancel' event to itself.






Re: Recommended way of cancelling a non-composite activity

Aleydis

Thanks, Sonali.

Now I know for sure. At the moment I'm still in an early stage with our project and can change our base activities from plain to composite ones.

Aleydis






databaseforum