- 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)
{
}
}
}
}
}
}