WWF - Cancels an activity execution when an exception occurs

  • Thread starter Thread starter Cesar
  • Start date Start date
C

Cesar

Hey folks.

This question is about Windows Workflow Foundation and exception handling.

I have a HandleExternalEventActivity activity that runs some code when the
user clicks an "Accept" button on my form. The activity includes several
tasks that involves database and eventually filesystem.

The problem is, when an exception occurs within that activity, the workflow
is set to Terminated. That ruins the flow, because even if I can trap the
exception (throw to the host)
, the user will not be able to click the Accept button anymore, because the
workflow state will be erased.

In short, is there a way to catch the exception inside the activity and
return it like if it was never called? (same as a rollback).

I tested FaultHandlers, not good. And I have searched a lot, but can't find
this "activity rollback" behaviour.

I appreciate help. :D

*Ps*.: just to know the way of working, I wish this:
1. user clicks accept button;
2. wwf throws an exception;
3. the host application traps and tells user to fix whatever data is wrong;
4. user clicks accept again;
5. wwf continues to trhow exception till everything is ok. If all ok, commit
the regular way long.


Cesar
 
You can look into compensation that work with or without
FaultHandlerActivity: CompensatableSequenceActivity and CompensateActivity
(but do not confuse the two).

Or even just FaultHandler would do it (assume it is a sequencial workflow):

you place the EventDrivenActivity's container (a ListenActivity?) in a
WhileActivity loop, and set a flag in the workflow to indicate whether
"Accept" process is done successfully or not, the workflow will be in a loop
to listen the "Accept" event until "Accept" process is done. If the
exception happens, the FaultHandler catch it (so that your workflow is not
terminated), the ListenActivity is done, but the "Accept" flag is not set,
so the workflow will loop back due to WhileActivity. Of course you may want
to have some sort of notification if the "Accept" process repeatedly throws
out exception (or the user knows to whom he/she should report for this
failure), so that your workflow would not be stuck there.
 
Hmmm... I was trying to escape from setting a loop to fix that, for the
reason not turning the workflow too complex (I have about 8 ListenActivities
on it).

But since it seems there are no simpler manner to do it, then I'll go for
it.

Thanks!
Cesar

PS: Btw, its a confuse logic to follow. The expected way to work would be:
"if something was wrong, lets cancel it". And not "if something was wrong,
lets continue the work, as it was not important". Any way to suggest an
improvement to wwf team?
 
Back
Top