Creating execution contexts/running closed activities
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: controlActivity.Closed += new EventHandler<ActivityExecutionStatusChangedEventArgs>(controlActivity_Closed); 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: 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?
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
foreach (Activity activity in this.EnabledActivities)
{
if (activity is ControlFlow.ControlActivity)
{
ControlActivity controlActivity = (ControlActivity)activity;
}
}
return base.Execute(executionContext);
}
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);
}

