Suspending a WF Program Instance
A running WF program instance can be
Listing 5.15. SuspendActivity
Use of SuspendActivity in XAML looks like this:
<wf:SuspendActivity x:Name="s1" Error="Please fix xyz" />
A suspended WF program instance is not allowed to proceed further in its execution, even if there is work enqueued in its scheduler work queue. The instance remains in a suspended state until the
Resume
method of its
WorkflowInstance
is called. The
Error
property of
SuspendActivity
(and the equivalent string parameter of the
Suspend
method of
WorkflowInstance
) can be used to
The WorkflowRuntime has a WorkflowSuspended event, which is raised whenever a WF program instance is suspended. Listing 5.16 illustrates this process. Listing 5.16. WF Program Instance Suspension
WorkflowInstance.Suspend stops the execution of the WF program instance, and also causes the WorkflowRuntime to raise the WorkflowSuspended event. The suspended WF program instance remains in memory; if a host application wishes to unload the instance, the Unload method can be called as well (for example, from within the handler of the WorkflowSuspended event). A WF program instance that has been suspended must always be explicitly resumed in order for its execution to continue; it is not enough to simply load a suspended instance that was previously unloaded.
Calling
Resume
on
WorkflowInstance
will resume the program's execution from wherever it had left off. Calling
Resume
has no effect in
|
Terminating a WF Program Instance
A WF program instance can be
Listing 5.17. TerminateActivity
Use of TerminateActivity in XAML looks like this:
<wf:TerminateActivity x:Name="t1" Error="Cannot proceed" />
The
WorkflowRuntime
has a
WorkflowTerminated
event, which is raised whenever a WF program instance is terminated. Termination of a WF program instance is
Listing 5.18 shows the WorkflowTerminatedEventArgs type. Listing 5.18. WorkflowTerminatedEventArgs
Calling
WorkflowInstance.Terminate
causes the execution of the program instance to end immediately. As part of termination, the WF program instance is persisted and removed from memory. Although a WF program instance is
Listing 5.19. WF Program Instance Termination
|