WF from entry to mastery (chapter 2): Notes for running Workflow

Source: Internet
Author: User
  1. Workflowruntime

Table 2-1 attributes of workflowruntime

Attribute Function
Isstarted This parameter indicates whether a workflow instance has been started and is ready to accept. Isstarted is false before the host calls startruntime. It remains true until the host calls "stopruntime. Note that when it is running, you cannot add core services.
Name Obtain or set the name associated with workflowruntime. You cannot set this attribute when workflow is running (that is, when isstarted is true ). The result of this attempt is an "invalidoperationexception" exception.

Table 2-2 workflowruntime

Method Function
Addservice Add the specified service when running workflow. The service types and time that can be added are subject to various restrictions. The service details are described in Chapter 5.
Createworkflow Create a workflow instance that contains specified (but optional) parameters. If workflow is not started during running, this method calls the startruntime method.
Getworkflow You can retrieve a workflow instance by specifying its identifier (consisting of a guid. If the workflow instance is idle and permanently saved, it will be reloaded and executed.
Startruntime Start the workflow runtime and related services, and raise the "started" event.
Stopruntime Stop workflow runtime and related services, and raise the "stoped" event.

Table 2-2 workflowruntime events

Event Function
Started Triggered when workflow is started.
Stopped Triggered when Workflow stops running.
Workflowcompleted Triggered when a workflow instance is complete.
Workflowidled Triggered when a workflow instance is idle. When a workflow instance enters the idle state, you have the opportunity to detach it from the memory, store it to the database, and load it into the memory later.
Workflowterminated Triggered when a workflow instance is terminated. A workflow instance's terminate method is called in the host, or is terminated when a terminate activity is used, or when a workflow runs, an uncaptured exception is generated.

2. workflowfactory. CS

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. workflow. runtime;

Namespace workflowhost
{
Public static class workflowfactory
{
// A single instance of workflow Runtime
Private Static workflowruntime _ workflowruntime = NULL;
Private Static object _ syncroot = new object ();
// Factory Method
Public static workflowruntime getworkflowruntime ()
{
// Prevent concurrent access in a multi-threaded Environment
Lock (_ syncroot)
{
If (null = _ workflowruntime)
{
Appdomain. currentdomain. processexit + = new eventhandler (stopworkflowruntime );
Appdomain. currentdomain. domainunload + = new eventhandler (stopworkflowruntime );
_ Workflowruntime = new workflowruntime ();
_ Workflowruntime. startruntime ();
}
}
Return _ workflowruntime;
}
Static void stopworkflowruntime (Object sender, eventargs E)
{
If (_ workflowruntime! = NULL)
{
If (_ workflowruntime. isstarted)
{
Try
{
_ Workflowruntime. stopruntime ();
}
Catch (objectdisposedexception)
{
}
}
}
}
}
}

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.