Is it possible to get running workflow instances in code?


We currently have an issue with the My Tasks list in the CMS. The AJAX service it goes to returns a 404 when a page referenced by a running workflow instance no longer exists (delete page and clear recycle bin). This means the entire My Tasks list fails to work.

As a workaround, we would like to be able to get a list of all currently running workflow instances of type "Parallel Approval" in code, so that we can delete those which have invalid content references associated with them.

Is it possible to -

  • List all running workflow instances in code
  • Delete a running workflow instance in code


Sep 11, 2014 11:13

Hi Jallen,

1. List all running workflow instances in code:


2. Delete a running workflow instance in code:

WorkflowSystem.InstanceHandler.TerminateInstance(instance.InstanceId, "Terminate instance from code");

Hope that help!


Sep 12, 2014 6:48

That's perfect, thanks!

Sep 12, 2014 9:43

If anyone has a similar problem to what I described in OP, this is the code I have in my scheduled job now to fix the problem. Hopefully someone else will find it useful -

var instances = WorkflowSystem.InstanceHandler.GetInstances(AccessLevel.NoAccess);
_numTotalInstances = instances.Count;
_numDeletedInstances = 0;
foreach (var instance in instances)
    if (_stop)

    catch (ContentNotFoundException ex)
        WorkflowSystem.InstanceHandler.TerminateInstance(instance.InstanceId, "Invalid page reference", AccessLevel.NoAccess);
Sep 12, 2014 10:39

Nice code Jallen! Thanks!

// Ha

Sep 12, 2014 12:10
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.