Search This Blog

Friday, April 8, 2011

Some Tips on Loading and Unloading Workflow


WorkflowInstance.Unload:
As we know, WorkflowInstance.Unload is the method that the host application can call in order to passivate a WF program instance. WorkflowInstance.TryUnload differs from Unload in that it will succeed only if the instance is idle or suspended. If the instance is doing any work (the scheduler thread is active) when tryUnload is called, a value of false is returned and there is no effect on the instance.


Every WF program instance has a globally unique instance identifier associated with it. Thus, the host application can load a previously saved (passivated) WF program instance by calling WorkflowRuntime.GetWorkflow passing the required identifier. GetWorkflow causes the program instance to be loaded into memory from the store provided by the persistence service. If the host application already holds a WorkflowInstance for a passivated instance, the instance can be loaded by calling WorkflowInstance.Load, as shown here:

   1:  using (WorkflowRuntime runtime = new WorkflowRuntime())
   2:  {
   3:    runtime.StartRuntime();
   4:   
   5:    WorkflowInstance instance = runtime.CreateWorkflow(type);
   6:   
   7:    instance.Start();
   8:    ...
   9:    instance.Unload();
  10:    ...
  11:    instance.Load();
  12:    ...
  13:  }

There is no fundamental difference between WorkflowRuntime.GetWorkflow and
WorkflowInstance.Load , Typically, a passivated instance is loaded in order to deliver stimulus that has arrived from the external world:

   1:  Guid handle = ...
   2:  WorkflowInstance instance = runtime.GetWorkflow(handle);
   3:  instance.EnqueueItem(...);

No comments:

Post a Comment