Windows Workflow Foundation, Exceptions and retry's?
-
07-07-2019 - |
Question
I have a sequential workflow with a number of Activities. One of these activities needs to access my paid S3 account. It works fine, but to be cautious, I would like to make sure it can handle unexpected situations, such as 'Host not found' or some timeout, etc.
So .. i would normally put the code inside a TRY / CATCH. That's fine .. but i'm not sure of what i should do with the workflow .. because if the code fails to complete correctly, the rest of the workflow shouldn't occur (based on the logic of this workflow).
So, i wanted to maybe retry the connect a few times .. and if that finally fails, call an Email Activity and terminate workflow.
Can anyone make any suggestions, links to vid's or screenies that help show what is the best practice for this?
cheers!
Solution
Take a look at the FaultHandlerActivity
, which is used to handle an Exception of the type specified by the FaultType
property. Some links about error handling in WF:
- Fault Handling in Workflows
- Using the FaultHandlerActivity Activity
- Exception and Error Handling (partial book chapter)
Another way is to use the Activity.HandleFault
method, which is called when an exception is raised within the context of the execution of your activity.
OTHER TIPS
You might also want to have a look at this blog article on a custom Retry activity: http://www.pluralsight.com/community/blogs/matt/archive/2007/11/28/49315.aspx
Looks like it is just what you might need!