locked
Terminate activity throwing exception RRS feed

  • Question

  • Hi all,

     

    I am using Terminate activity in my sharepoint 2007 workflow. But when my workflow is running and passing through this activity then its terminates the workflow and also logging an exception information in workflow history list saying "Exception of type 'System.Workflow.ComponentModel.WorkflowTerminatedException' was thrown." 

     

    What should i do to remove this exception???

    Wednesday, April 25, 2007 10:31 AM

Answers

  • Hi,

     

    First of all you really shouldn't use the terminateactivity to end your workflow.

     

    From the documentation

    "When an abnormal situation occurs, you can use a TerminateActivity activity to immediately end all activities of a running workflow instance."

     

    One really good reason why not to use it is that parallel branches wont get the possibility to do cleanup/cancel and so on.

     

    If you need a good way to close your workflow you could

     

    1. Modify the workflow in runtime and remove/disable upcomming activities

    2. Use if/else to route the workflow in another direction

    3. Throw a exception (ie your own MyWorkflowIsCanceling exception) and catch it in the workflow's faulthandler

     

    Regards,

    Daniel Karlsson

    http://workflowfoundation.blogspot.com/

    Wednesday, April 25, 2007 10:52 AM

All replies

  • Hi,

     

    First of all you really shouldn't use the terminateactivity to end your workflow.

     

    From the documentation

    "When an abnormal situation occurs, you can use a TerminateActivity activity to immediately end all activities of a running workflow instance."

     

    One really good reason why not to use it is that parallel branches wont get the possibility to do cleanup/cancel and so on.

     

    If you need a good way to close your workflow you could

     

    1. Modify the workflow in runtime and remove/disable upcomming activities

    2. Use if/else to route the workflow in another direction

    3. Throw a exception (ie your own MyWorkflowIsCanceling exception) and catch it in the workflow's faulthandler

     

    Regards,

    Daniel Karlsson

    http://workflowfoundation.blogspot.com/

    Wednesday, April 25, 2007 10:52 AM
  • Daniel,

     

    I have a related problem I hope you don't mind me asking.  I've built several custom workflows with VS 2005 and they all work just fine, except for one problem - after my workflow(s) finishes, if I check the status under Settings->Workflow settings-> my workflows always show a non-zero value in "Workflows in Progress".  It never shows zero, always increments each time I start my workflow.  I must not be terminating my workflow or something.  In VS, I've only added the activities I need to perform my functions.  Is there something else that is needed to terminate the workflow when it finishes successfully so I doesn't appeart in the "Workflows in Progress"?

     

    Thanks for any help,

    Kevin

    Tuesday, May 29, 2007 8:39 PM
  • Hi kevin

     

    Strange, I'm guessing that your workflows are associated with a list in sharepoint. This list should have a column representing your workflow association, what's the state of each instance according to this column? You can also click each item in the column to get more information about the workflow.

     

    If you are creating tasks you have to close them in order for your workfow to complete and therefore a quick view in the workflowtasks list might be a good idea.

     

    Regards,

    Daniel Karlsson

    http://workflowfoundation.blogspot.com/

    Wednesday, May 30, 2007 5:57 AM
  • Hello,

     

    I am using the Terminate activity as well.  What you need to do is set the error property on the activity.  For example mine is Error: Workflow has been terminated by the AD.  What shows up in the history log is "Workflow has been terminated by the AD".

    Thursday, May 31, 2007 2:50 PM
  • Please note that this is a bad way to end the workflow since no cancel/compensation-handlers and so on will be called.

     

    Read my first post carefully

     

    Regards,

    Daniel Karlsson

    http://workflowfoundation.blogspot.com/

    Thursday, May 31, 2007 3:03 PM
  • I had also the problem to cancel a workflow for a certain item and I used:
    SPWorkflowManager.CancelWorkflow(workflow) where workflow is the instance of the workflow you want to cancel
    This worked for me!




    Tuesday, June 19, 2007 10:21 PM