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 ");