Creating execution contexts/running closed activities

I have a sequential

workflow and 3 child activities. Now my goal is to make my workflow

execute again from activity 1 when I'm finishin to execute the second

activity (return back). What I'm doing to achieve that is overriding

the Execute method on my workflow to provide some custom behavior and

bind to the Closed event of each workflow. Like this:

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{
foreach (Activity activity in this.EnabledActivities)
{
if (activity is ControlFlow.ControlActivity)
{
ControlActivity controlActivity = (ControlActivity)activity;

controlActivity.Closed += new

EventHandler<ActivityExecutionStatusChangedEventArgs>(controlActivity_Closed);
}
}
return base.Execute(executionContext);
}

Then

in the controlActivity_Closed method checking on condition I say that I

need the workflow to pass executing some previous activity by creating

a new context:
void controlActivity_Closed(object sender, ActivityExecutionStatusChangedEventArgs e)
{
ActivityExecutionContext senderContext = (ActivityExecutionContext)sender;
string targetActivityName = (string)UserData["LastActivityName"];
ControlActivity targetActivity =
(ControlActivity)this.GetActivityByName(targetActivityName);
ActivityExecutionContext newContext =
senderContext.ExecutionContextManager.CreateExecutionContext(targetActivity);
newContext.ExecuteActivity(newContext.Activity);
}

And

the workflow starts executing from the first activity, but somehow it

will instantly get executing to the third one not managing to finish

activity 1 and 2. It seems to be executing the 1 and third activity in

parallel. My clue is that the 1st and 2nd activities are already in the

closed state that's why the workflow starts to execute activity 3 that

is initialized and I know that the contexts may execute activities in

the parallel. So, my goal was to return execution to some activity

back, how do I achieve that?

[4024 byte] By [SLV] at [2007-12-25]
# 1

Have you setup and tracking to see exactly where you are in the workflows?

Plus you are not say much of the workflow itself. How do you have it laid out? What kind of activities are you using for the three activities?

Bill

BillZunis at 2007-9-3 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2

I've posted the question long ago and that's what I figured out since then: if I override the Execute method of a SequenceWorkflowActivity and then try to make it return to a previous step creating new contexts it will create the contexts, but also continue to execute from the point where I wanted to move back. So as I studied more the WF I got to the answer that in order to provide custom execution behaviour into the parent workflow I must derive exclusively from CompositeActivity and implement IActivityEventListener and it's gonna work with the back functionality.

My solution was to create my own custom CompositeActivity that will serve as parent for the other activities that I'll be working with.

SLV at 2007-9-3 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3
Could You put a simple sample of code that using Your solution, I'm working on the same problem, for now without ideas
Thanks
robertkwapiszewski at 2007-9-3 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4

This is an example that you may follow to create your workflow and change it to provide custom logic into it. Also there are examples on creating custom activities in the downloads on the wf.netfx3.com web site

public partial class CustomWorkflowActivity : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>

{

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

Activity firstChildActivity = EnabledActivities[0];

firstChildActivity.RegisterForStatusChange(Activity.ClosedEvent, this);

executionContext.ExecuteActivity(firstChildActivity);

return ActivityExecutionStatus.Executing;

}

public void OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)

{

ActivityExecutionContext executionContext = sender as ActivityExecutionContext;

if (executionContext == null)

throw new ApplicationException("Activity execution context cannot be null.");

e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);

//creating next activity context

ActivityExecutionContext childExecutionContext =

executionContext.ExecutionContextManager.CreateExecutionContext(EnabledActivities[executeCtrlActivityIndex]);

childExecutionContext.ExecuteActivity(childExecutionContext.Activity);

}

}

SLV at 2007-9-3 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified