0

I'm trying to start a workflow programmatically at the end of another workflow. Everything works fine, except that the new workflow is not started immediately, but queued for execution. This is how I start the workflow:

SPListItem currentItem = workflowProperties.Item;

SPWorkflowAssociation wfAssociation =
    currentItem.ParentList.WorkflowAssociations.GetAssociationByBaseID(
        new Guid("next-workflow-guid"));

SPWorkflow nextWorkflow = currentItem.Web.Site.WorkflowManager.StartWorkflow(
    currentItem,
    wfAssociation,
    wfAssociation.AssociationData,
    true);

I read about the timer service, that is responsible for the workflow execution, and checked the corresponding property:

PS C:\Windows\system32> STSADM -o getproperty -pn job-immediate-alerts -url "http://my-sp-site/"
<Property Exist="Yes" Value="every 5 minutes between 0 and 59" />

Is there any way to work around the timer and say something like "Timer, please go and check now if there is anything on your queue" ?

0

Starting with SharePoint 2010 all programmatically initiated workflows are queued for execution by the timer service ( in other words, this behavior is by design). We encountered this issue when we migrated some workflow code from 2007 to 2010. Despite looking long and hard we were never able to find a way to selectively override the behavior.

The workflow engine sees the initiation of another workflow as a good execution save point and will always save the state and wait for the timer service to continue operations in the new workflow.

If your first workflow makes any changes to the item in question is there any chance you could use an event handler for the logic currently in the second workflow? If you need immediacy of execution this would probably be the better way to go as workflows, by their definition, are oriented for longer running activities where immediacy is not required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.