0

I am bit new to Windows Workflow foundation so it might be a very straight forward, but I am stuck with it. I've a very simple sequential workflow and there are couple of code activities that are inside a Transaction Scope Activity.

I am running my workflow from Console application having following code:

        Activity workflow = new Process();
        var inputArgument = new Dictionary<string, object>();
        inputArgument["Argument 1"] = 1234567;
        inputArgument["Argument 2"] = 1234567;
        inputArgument["Argument 3"] = "GUID";
        inputArgument["Aggument 4"] = @"\\filepath\";

        var syncEvent = new AutoResetEvent(false);

        var workflowApp = new WorkflowApplication(workflow, inputArgument);

        workflowApp.OnUnhandledException =
            delegate (WorkflowApplicationUnhandledExceptionEventArgs e)
            {
                return UnhandledExceptionAction.Terminate;
            };

        workflowApp.Completed +=
            delegate (WorkflowApplicationCompletedEventArgs e)
            {
                syncEvent.Set();
            };

        workflowApp.Run();

        syncEvent.WaitOne();

If I don't add Transaction Scope activity my workflow runs fine and in case of exception the workflow instance terminates and my console application close as well.

However, when I add Transaction Scope activity and if any activity fails inside Transaction Scope then my workflow instance keep running as well as my console. Can any one guide me how to terminate the instance?

I am not handling any exception within my workflow and want it to be like that so that I can log the exception details.

Nido
  • 241
  • 4
  • 22

1 Answers1

2

If you go to properties on the TransactionScope in the Workflow there is a property that is set to true by default called AbortInstanceOnTransactionFailure. Set that to false. It should then behave as you're expecting.

When this is enabled it will cause the workflow instance to abort but not terminate.

helmsb
  • 231
  • 1
  • 5
  • Thanks, it worked. Just for my knowledge can you let me know if it is better to keep `AbortInstanceOnTransactionFailure` to `True` or `False`. My Worflow will be initiated from WCF service as well as from Console. – Nido Feb 18 '16 at 14:36
  • Setting it to `false` propagates the exception back up to the caller. When it's `true` it just silently executes the rollback. I've never found an instance where I **didn't** want to be notified of an exception so I've always set that property to `false`. I think in both of your use cases leaving it as `false` makes sense and nearly every transaction WF example I've seen has it set to `false`. – helmsb Feb 18 '16 at 14:54