共用方式為


WorkflowInstance.TryUnload 方法

定義

執行個體暫止或閒置時,將工作流程執行個體從記憶體卸載到持續性存放區中。

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

傳回

如果工作流程執行個體已卸載則為 true,否則為 false

例外狀況

沒有已經向工作流程執行階段引擎註冊的持續性服務。

範例

下列程式碼範例將示範如何使用 TryUnload 方法在 WorkflowIdled 事件引發時卸載工作流程。 這個範例是 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 回 。 Unloadfalse如果工作流程實例已經卸載、已終止、已中止或已完成,則傳回 。

主機可以使用 TryUnload 從閒置的工作流程中回收系統資源。

適用於