Workflow Life Cycle
[Applies to: Microsoft Dynamics CRM 4.0]
The life cycle of a workflow describes the state transitions from creation through execution. A workflow can be in one of the following states: Ready, Suspended, Locked, and Completed. The workflow events that occur throughout the lifetime of the workflow cause a transition from one state to another.
During the activation of a workflow, the workflow subscribes to specific Microsoft Dynamics CRM events. When these events are fired in the platform, a snapshot of the workflow dependencies and input parameters are created and a new asynchronous operation is added to the asynchronous service queue manager. The asynchronous operation represents a workflow execution job and awaits execution in the queue in the Ready state.
When the asynchronous operation is processed, a workflow instance, associated with this operation, is created by the Windows Workflow Foundation run-time engine and the state of it is changed from Ready to Locked.
The asynchronous operation is updated with the workflow instance state status on each transition. When the asynchronous operation is blocked, the Windows Workflow Foundation run-time engine puts the workflow instance into the Suspended state and removes it from the memory. When the Suspended state conditions are satisfied, the workflow instance is loaded back into the memory.
The workflow execution resumes by putting the workflow instance into a Ready state and then into a Locked state. In the simple scenario, the workflow instance moves to a Completed state when all workflow activities have completed successfully.
The state of asynchronous operations can also be changed by the user. For example, an asynchronous operation that is in a Suspended state can explicitly be restarted by the user.
The following diagram shows how the user can interact with the asynchronous operation for a workflow.
Avoiding a Workflow Infinite Loop
A poorly designed workflow can result in an infinite loop where the workflow runs indefinitely, using up available system resources like memory and disk space. For example, consider a workflow that creates an account that is registered to run when an account is created. When a user creates an account, the workflow runs and creates another account that causes the workflow to run again, and so on.
Microsoft Dynamics CRM has run-time logic to find and stop workflows that have entered an infinite loop. The system automatically stops the workflow. To see this, you can check the workflow status in the Web application as shown in the following screenshot.
You can correct this problem by changing the design of your workflow. In the situation when a workflow needs to loop through code indefinitely, you should take care to limit the number of loops to less than 7 per hour. You can do this by inserting a one hour time-out in your workflow.
© 2010 Microsoft Corporation. All rights reserved.