Share via


WorkflowInstance.TryUnload 方法

定义

当实例处于挂起或空闲状态时,将工作流实例从内存卸载到持久性存储区。

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

返回

如果已卸载工作流实例,则为 true;否则为 false

例外

不存在已注册到工作流运行时引擎的持久性服务。

示例

下面的示例演示如何在 WorkflowIdled 事件激发时使用 TryUnload 方法卸载工作流。 此示例摘自 Program.cs 文件中的“使用持久性服务”SDK 示例。 有关详细信息,请参阅 使用持久性服务示例

//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

注解

如果工作流实例处于“空闲”或“挂起”状态,则 TryUnload 将使用持久性服务从内存中移除此工作流实例,并将其保留到数据存储区。 如果不存在使用 WorkflowRuntime 注册的持久性服务,则 TryUnload 将引发 InvalidOperationException。 如果工作流实例成功保留,则运行时将引发 WorkflowUnloaded 事件,并返回 true。 如果工作流实例已卸载、已中止或已完成,则 Unload 将返回 false

宿主可以使用 TryUnload 回收空闲工作流的系统资源。

适用于