WF framework programming (activity Finite Automaton and WF instance scheduling)

Source: Internet
Author: User

Part 2 continued

Iii. Scheduling 1 WF Runtime (workflowruntime)

Namespace: system. workflow. runtime. workflowruntime

File: system. workflow. runtime. dll

Key points:

1. Resident in CLR, that is, CLR needs to instantiate a workflowruntime object

2. workflowruntime runs independently in the host (for details, see the WF thread model Section)

3. workflowruntime can load multiple workflow instances. Each workflow instance has an independent thread in workflowruntime.

4. the same host can instantiate multiple workflowruntime, and they can work simultaneously.

The WF loading part should be locked. Will affect the WF program queue.

Is a service container. You can add a definition service, a WF runtime service, and a service provided to activity.


For more information, see wxwinter's blog.

2. Analysis of the Structure of the limited automatic machines 2.1 acitivity and compositeaciti.pdf IN THE ACTIVITY

For more information, see the wxwinter blog,Vs. Check out the msdn help. It is also recommended.


2.2 acitiworkflow Automation

It can be understood as the lifecycle of acitivity.

Image Source: essential. Windows. workflow. Foundation
Suceeded is written as closed.

2.3 scheduler queue

The workflow queue of the WF scheduler in non-preemption mode.

2.4 WF program queue

Communication channel between the host and WF

Image Source: essential. Windows. workflow. Foundation

3 WF scheduling 3.1 logical lifecycle of WF

Refer to essential. Windows. Workflow


The logical life cycle of WF is not the life cycle of CLR objects. When CLR is not persistent, it temporarily represents activity in memory. The promoter of the activity is AEC. Runtime does not care about the status of each activity.

3.2 Relationship Between the life cycle of acitivity and the logical life cycle of WF instances

Image Source: essential. Windows. workflow. Foundation

Activity lifecycle:Initialize, exeute, continueat, onclose, uninitialize

Important:WF does not care about the next acitivity and when it will flow.

3.3 WF instance Lifecycle


Image Source: essential. Windows. workflow. Foundation

Instance Creation


You can use codedom or directly activate it to obtain the WF program prototype (which can be understood as an instance template) and then obtain multiple instances. The instance metadata points to the prototype metadata. If a prototype exists in the cache, create it directly. If it does not exist, add it to the cache. After creating an instance, you must create a scheduler and bind the instance object to the scheduler and AEC. The START instance (STAR) is the exeute method that adds the root node to the scheduler's work queue.

Loader implementation


Workflowloaderservice subclass. You can customize the loading service to load other DSL-defined processes.

Instance Passivation

Is the process of merging persistence save and destroy (workflow. Unload). Here you only need to know the concept. For detailed procedures, see the WF persistence section.

Instance suspension:

Implemented by instance. Suspend (string error) or suspendactivity. Pause the execution of the WF instance, and the instance will still reside in the memory. To uninstall the instance from the memory, you need to explicitly call workflowinstance. Unload () method.

For instances after suspend, the task is not executed even if the scheduler queue contains work items. You must explicitly call workflowinstance. Resume () before the instance can resume execution.

The pending information can be passed in through the error attribute and through the workflowsuspendeventargs. Error attribute.

Instance suspension:

Implemented by instance. Terminate (string error) or terminate activity. The workflowterminated event of workflowruntime is triggered. The event parameter workflowterminateargs contains exception and workflowinstance. The tracing service can also query this exception. Instance. Complete: The workflowcompleted event that triggers the runtime. outputparameters of workflowcompletedeventargs is the output parameter, which can be used to obtain all public attributes of the root activity.

Instance. Abort: triggers the workflowabort event during running. The last persistent task is discarded and the instance is removed from the memory.

3.4 relationship between WF instance state machine and activity state machine

The method used by the host to schedule an instance. The instance enters a certain state, and the specific changes are the responsibility of the activity itself. The status of the activity also affects the status of the Instance (for example, the root activity unintialize, And the instance enters the comleted State)

Instance status changes and some behaviors can trigger running events.

4. Activity context activityexecutioncontext

Activityexecutioncontext and activityexecutioncontextmanager


1. provides services and implements the iserviceprovide interface. You can get the service added by workflowruntime. addservice through getservice.

2. scheduling status API, which can communicate with the Scheduler

3. Save status information

For example, the context to be saved during persistence (internal execution status, scheduler working queue status, and event subscription information)

Aecmanger. completexecutioncontext-> activity. onactivityexeutioncontextunload;

Activityexecutioncontextmanage provides the CREATE, complet, and get AEC capabilities.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.