locked
TerminateWorkflow activity & WorkflowInvoker.Invoke - BUG ? RRS feed

  • Question

  • Hi.

    I'm trying to terminate a workflow using TerminateWorkflow activity and i have some questions (it is not working as it should).

    Create a project and:

    1. Add a new Activity (MyDesignerActivity) in the project, and,in DesignerMode, add a sequence and into the sequence add a TerminateWorkflow activity (set just the Reason field).

    2. Add a new CodeActivity to project, and in the Execute method add this:

    MyDesignActivity a = new MyDesignActivity();
    WorkflowInvoker.Invoke(a); 

    3. Create a workflow: add a flowchart activity, inside it add a trycatch activity and inside try block add MyCodeActivity.

    4. Create a workflow: add a flowchart activity, inside it add a trycatch activity and inside try block add MyDesignActivity.

    Now run both workflows (using Invoke method from WorkflowInvoker)

    For the first workflow (step 3), the application (WF) will finish successfully. For the second one, the run will failed with an Exception.

    My question is, why we have two different behaviors?

    Monday, May 2, 2011 8:08 PM

Answers

  • Found the answer: http://connect.microsoft.com/wf/feedback/details/557601/try-catch-activity-never-executes-finally-if-exception-propagate.

    • Marked as answer by Silviu Luca Tuesday, May 3, 2011 9:00 AM
    Tuesday, May 3, 2011 9:00 AM

All replies

  • Found the answer: http://connect.microsoft.com/wf/feedback/details/557601/try-catch-activity-never-executes-finally-if-exception-propagate.

    • Marked as answer by Silviu Luca Tuesday, May 3, 2011 9:00 AM
    Tuesday, May 3, 2011 9:00 AM
  • I see you've already accepted an answer but I interpreted your question a little differently.

    In one example you have a Workflow (B) called via WorkflowInvoker within another Workflow (A). Note that invoking a 'child' workflow in this way creates a completely separate instance of workflow B and this isn't related to Workflow A in any meaningful way.

    As you have observed, when the TerminateWorkflow activity is used, it causes the Instance to throw an Exception. The TerminateWorkflow activity itself does not behave like an exception so it cannot be 'caught'.

    However, when you call a 'child' workflow in code it results in a real exception. This can be caught and hopefully explains the reason why the behavior appears different.

    What happened was this

    Workflow A > Invokes (in code) Workflow B - creating a NEW and SEPARATE instance > Workflow B 'Terminates' > Workflow B instance throws a CLR exception > Workflow A handles this exception > Completes normally

    example 2

    Workflow A > 'Invokes' (in WF) Workflow B - this becomes part of the SAME instance > Workflow B 'Terminates' > Workflow B & A are running in the same instance and are terminated > WorkflowApplication throws a WorkflowTerminatedException.

    Hope that's useful to you or somebody else trying to understand the behavior here.


    www.thejoyofcode.com
    Tuesday, May 3, 2011 9:17 PM