Aborting a WF Program Instance


WorkflowInstance also carries an Abort method. When a WF program instance is aborted, the progress of the instance since its most recent persistence point is discarded, and the instance is evicted from memory. Unlike Terminate, the Abort method does not persist the instance, and it leaves the program instance in the Running state; it is as if the execution of the instance since the last persistence point did not ever happen.

The WorkflowRuntime has a WorkflowAborted event, which is raised whenever a WF program instance is aborted, as shown in Listing 5.20.

Listing 5.20. WorkflowInstance.Abort

 static void Main() {   using(WorkflowRuntime runtime = new WorkflowRuntime())   {     runtime.StartRuntime();     runtime.WorkflowAborted += delegate(       object sender, WorkflowEventArgs e)     {       Console.WriteLine("Instance aborted: " +         e.WorkflowInstance.InstanceId);     };     WorkflowInstance instance = ...     instance.Abort();     ...   } } 


The abort capability is perhaps best explained with an analogy. When you edit a document in an application such as Microsoft Word, it is typical to periodically save your work; this is analogous at some level to persisting a running WF program instance. When you close the Word document, you are asked whether the changes you have made to the document since the last time you saved it should be kept or discarded. If you discard the changes, the next time you open the document you will see it as it existed at the last point it was saved. So it is with the Abort method of WorkflowInstance; it simply discards the progress that was made in the execution of the program instance since its last persistence point.




Essential Windows Workflow Foundation
Essential Windows Workflow Foundation
ISBN: 0321399838
EAN: 2147483647
Year: 2006
Pages: 97

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net