dhrm
dhrm

Reputation: 14944

How to handle failures in parallel activities

I've a workflow in Windows Workflow Foundation. I've created a Parallel group, where I've placed four activities which extends the NativeActivity.

The activities are calling a remote web service, and if anything goes wrong in the call (maybe business rules), I suspend the activity by creating a Bookmark on the NativeActivityContext. This is not doing very well, if more then one of the activitites fails, as they are using the same bookmark name (SuspendBookmark).

Is it possible to extend the parallel behavior in some way, and maybe handling the failures here instead of each activity inside the parallel call?

Another thing, if one activity success and another fails, what would happen if I resume from the suspended bookmark in the failed activity? Would it run each activity in the parallel call again or would I just rerun the failed activity?

I need some information on how to implement these parallel calls in my workflow and how to handle failures in these.

Upvotes: 0

Views: 240

Answers (2)

Joao
Joao

Reputation: 7486

If I understood you well, you want to cancel parallel activity if any of its branches goes wrong. That way only one bookmark is created and you can resume it.

You've available CompletionCondition property on Parallel activity.

If this property evaluates to true, then the other scheduled elements in the Branches collection are canceled. If this property is not set, all Activity objects in the Branches collection execute until completion.

Just create a bool variable at parallel activity level and set it to true whenever something goes wrong.

If that doesn't work the way you want, nothing keeps your from creating your own custom parallel activity.

PS: Keep in mind that parallel activity is not really parallel. It waits in parallel for all the branches to execute but the execution itself is sequential (although order-independent).

Upvotes: 1

Mike
Mike

Reputation: 141

Maybe it will help if you consider activities as being of two different kinds (classes). One is a single, independent activity, which can fail or succeed and have its own book mark. The second type of activity is a 'composite' activity. This is a collection of activities that can also fail or succeed and possibly also have its own bookmark.

Upvotes: 0

Related Questions