This topic has not yet been rated - Rate this topic

WorkflowInstance.TryUnload Method

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

Namespace:  System.Workflow.Runtime
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)
public bool TryUnload()

Return Value

Type: System.Boolean
true if the workflow instance was unloaded; otherwise, false.
Exception Condition
InvalidOperationException

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

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.

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();
}


.NET Framework

Supported in: 4, 3.5, 3.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ