Dependency and Execution Order
[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
An asynchronous operation can be made dependent with another asynchronous operation. A dependent asynchronous operation does not execute until the operation that it is dependent with has finished executing. For example, if asynchronous operation B is dependent with asynchronous operation A, operation B does not execute until after operation A executes and is completed. This dependency between asynchronous operations is established by using the dependencytoken property of the asyncoperation class. The dependencytoken can contain any string value. However, the dependent asynchronous operations must have the same dependencytoken value.
The Microsoft Dynamics CRM platform establishes which asynchronous operation is dependent when the operations are created in the asynchronous queue. For example, consider three asynchronous operations named A, B, and C, where B and C should only execute after A is completed. To establish the correct dependencies, A must be created in the queue first, followed by B and then C. This is because the order in which the operations are created establishes the sequence of their execution. In this example, all three asynchronous operations have the same dependencytoken. At run time, A executes first. After A has completed, B executes to completion, and then C executes until completion.
In the previous example, if operation B is postponed, operation A executes until it is completed and operation C is blocked until operation B is no longer postponed and executes until completed. You can postpone execution of an asynchronous operation by using the postponeuntil property.
Any asynchronous operation that has a dependencytoken value of "null" executes independent of all other asynchronous operations in the queue. The order of execution with regard to other independent operations is not guaranteed. However, those asynchronous operations created earlier in time have a better chance of executing before those operations created later in time. This assumes that the operations are not postponed and are not set to a state of Completed.
© 2010 Microsoft Corporation. All rights reserved.