Wednesday, October 17, 2012

How to terminate suspended workflow instance?

While you are developing your workflow service, I believe you definitely would do a test run and then you encounter an error. At this time, you would go and fix your error, then you do another test run again. But, you keep getting the exception message something like unable to proceed due to workflow instance is in suspended state. So, what you can do now is to terminate the suspended workflow instance, and then retry with your fix.

How to terminate suspended workflow instance?

Execute the following code, be it in console application, unit test or whatever.
Note: The following code is for Workflow 4.0 or later. You need to add System.Activities and System.Activities.DurableInstancing assembly reference.

// Define workflow instance store.
SqlWorkflowInstanceStore instanceStore =
    new SqlWorkflowInstanceStore(
        ConfigurationManager.ConnectionStrings["WorkflowInstanceStore"].ConnectionString);


// Setup the workflow with a definition.
WorkflowApplication app = new WorkflowApplication(new MyWorkflow());


// Assign the instance store.
app.InstanceStore = instanceStore;


// Load the workflow instance.
app.Load(new Guid("[Put Your Instance's GUID Here]"));


// Restart the workflow execution.
app.Run();


// Terminate the workflow instance.
app.Terminate("Terminated due to unrecoverable errors.");


EDIT:
Credit to Serena for the source code. :P
 

No comments:

Post a Comment

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API. Transactional SMS usually come with One Tim...