แก้ไข

แชร์ผ่าน


WorkflowInstance.TryUnload Method

Definition

Unloads the workflow instance from memory to the persistence store when the instance is suspended or idle.

public:
 bool TryUnload();
public bool TryUnload ();
member this.TryUnload : unit -> bool
Public Function TryUnload () As Boolean

Returns

true if the workflow instance was unloaded; otherwise, false.

Exceptions

There is no persistence service registered with the workflow runtime engine.

Examples

The following example demonstrates using the TryUnload method to unload a workflow when the WorkflowIdled event fires. This example is from the Using Persistence Services SDK sample, from the Program.cs file. For more information, see Using Persistence Services Sample.

//Called when the workflow is idle - in this sample this occurs when the workflow is waiting on the
// delay1 activity to expire
static void OnWorkflowIdled(object sender, WorkflowEventArgs e)
{
    Console.WriteLine("Workflow is idle.");
    e.WorkflowInstance.TryUnload();
}
'Called when the workflow is idle - in me sample me occurs when the workflow is waiting on the
' delay1 activity to expire
Shared Sub OnWorkflowIdled(ByVal sender As Object, ByVal e As WorkflowEventArgs)
    Console.WriteLine("Workflow is idle.")
    e.WorkflowInstance.TryUnload()
End Sub

Remarks

If the workflow instance is idle or suspended, TryUnload uses the persistence service to remove the workflow instance from memory and persist it to a data store. If there is no persistence service registered with the WorkflowRuntime, TryUnload throws an InvalidOperationException. If the workflow instance is successfully persisted, the runtime raises the WorkflowUnloaded event, and returns true. Unload returns false if the workflow instance has already been unloaded, has been terminated, has been aborted, or has already completed.

The host can use TryUnload to reclaim system resources from an idle workflow.

Applies to