Introduction to MS wf4.0

Source: Internet
Author: User
How to run a workflow?

The code for using the WorkflowApplication class is as follows:

 

// Initial parameters

Dictionary <string, object> inputs = new Dictionary <string, object> ();

// Create a workflow instance

WorkflowApplication app = new WorkflowApplication (new Activity1 (), inputs );

// Use sqlserver to save the workflow status

App. InstanceStore = new SqlWorkflowInstanceStore ();

// Run the Workflow

App. Run ();

 

How do I wait for user input?

The workflow bookmarks function is used, but the existing bookmarks are not provided in WF. You need to customize an activity to create bookmarks for user input. The Code is as follows:

 

Public sealed class ParametersReciever: NativeActivity <WFParameters>

{

// Execute must be implemented. When the workflow goes to this activity, create a bookmark and wait for user input.

Protected override void Execute (NativeActivityContext context)

{

Context. CreateBookmark ("params", new BookmarkCallback (OnReadComplete ));

}

 

Void OnReadComplete (NativeActivityContext context, Bookmark bookmark, object state)

{

WFParameters input = state as WFParameters;

Context. SetValue (this. Result, input );

}

}

 

How do I return the workflow status?

Use the InvokeMethod activity, which can call static methods or object methods. Specific settings are shown in:

TargetType and TargetObject are mutually exclusive. The former indicates a class containing static methods, and the latter indicates an instance object.

 

Set parameters

How to terminate the process

Use the Terminate method of WorkflowApplication. The revocation process will be permanently terminated. The Code is as follows:

Dictionary <string, object> inputs = new Dictionary <string, object> ();

WorkflowApplication app = new WorkflowApplication (new Activity1 (), inputs );

App. InstanceStore = new SqlWorkflowInstanceStore ();

App. Run ();

Guid id = new Guid ("11b4b3e4-32db-4698-9fe2-5d783e23c65f ");

// Load the workflow instance

App. Load (id );

// Termination process

App. Terminate ("revocation process ");

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: info-contact@alibabacloud.com 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.