Dirk S.

Hello,

what is the best practice for the following scenario

Building a custom activity derived from Sequence Activity. If one of the child activities throws an exception this exception should be catched and logged (optional). Then the complete sequence of activites should be restarted (meaning we perform a retry on the complete sequence). If MaxNumberOfRetries (a property on the custom activity) is reached the exception will be thrown to the parent activity/workflow.

I tried many scenarios including overriding the HandleFault method, invoking inner contexts building custom FaultHandlers but none of them seems to work properly...

Thank You!

Dirk



Re: Windows Workflow Foundation ExceptionHandling with Retry

Vignesh Kannappan - MSFT

Hi Dirk -

I think a simpler solution would be to wrap this custom sequence activity inside a while activity. Since from your description it looks like we need to re-execute certain activities, while helps spawning new contexts for re-execution. Execution context for an activity, once it reaches a closed stated cannot go back to executing state. We prohibit such a transition in WF to enforce a execution state automaton.

You could have the while check the custom activities' MaxNumberOfRetires property with a counter that will be updated by the Cancellation handler of your new custom sequence activity. Until the condition is reached you'll keep re-executing the custom sequence which in-turn executes the containing children activity.

Does that help

Vignesh






Re: Windows Workflow Foundation ExceptionHandling with Retry

Chris Owczarek

I'm also looking for this sort of retry behaviour. Basically what I need is to be able to execute a sequence of activities in a retry loop with the following

requirements:

- If any activity throws an exception I want to either retry the sequence from the start or terminate the workflow instance.
- The decision to retry or terminate will be based on the type of exception.
- Between each retry I wish to wait a fixed delay period before retrying.
- During this delay, I need the workflow instance to be unloaded and persisted.
- If the retry limit is exceed, the workflow instance is terminated.

Ideally, I'd like to write a custom activity to encapsulate this behaviour so that in the designer you simply add to the activity and drop other activities on

to it. This has proven difficult. I've tried nesting a CompositeActivity within a WhileActivity and within the CompositeActivity I've added a

FaultHandlerActivity and a DelayActivity programmatically. As soon as I do that, the CompositeActivity becomes locked in the designer and you can't drop other

activities into it. If there is a straight forward way of getting around this designer locking I'd be interested. I've seen stuff on implementing your own

SequentialActivityDesigner or ActivityToolboxItem class which gives the impression it's easy but what I've seen hasn't made much sense so any useful pointers in this direction would be useful.

Alternatively, this retry behaviour could be constructed entirely in the designer using the mentioned activities. I can live with this as we only need retry

behaviour in a couple of places within our workflow so cutting and pasting such a construct shouldn't be an issue. However, I've hit a problem with this

approach. It works fine without persistence but as soon as persistence is enabled the DelayActivity (running in the FaultHandler activity) doesn't behave as

expected. The persistence service is configured with a LoadIntervalSeconds set to 5 secs and the DelayActivity timeout is set to 15 secs. Rather than the

activities being executed every 15 secs it seems that they get executed every 5 secs and in some cases twice without any delay. Kind of bizarre. Could anyone

shed some light on this

Regards, Chris.





Re: Windows Workflow Foundation ExceptionHandling with Retry

Chris Owczarek

With regards to the DelayActivity behaving strangely, we've found the problem. Because we have persistence turned on, simply ending the test program leaves live workflow instances in the persistence store. By restarting the program repeatadly, more live instances are accumulated. Hence the output shows timer expiry for all live instances each time the workflow runtime executes not just the one instance the program initiates.





Re: Windows Workflow Foundation ExceptionHandling with Retry

Felix Deierlein

Hello,

has anybody created a custom activity encapsulating that behavior and would like to share it
We are currently using while activities with sequenzes and fault handling.
But this makes the workflow complex.

Thanks & regards

Felix Deierlein