WorkflowApplication.Unload 方法

定義

保存或卸載工作流程執行個體。Persists and unloads a workflow instance.

多載

Unload(TimeSpan)

保存與卸載使用指定逾時間隔的工作流程執行個體。Persists and unloads a workflow instance using the specified time-out interval.

Unload()

保存或卸載工作流程執行個體。Persists and unloads a workflow instance.

備註

根據預設,卸載作業必須在 30 秒內完成,否則會擲回 TimeoutExceptionBy default, the unload operation must complete in 30 seconds or a TimeoutException is thrown.

如果先前已從持續性載入工作流程執行個體,則會使用用來載入工作流程的相同 InstanceStore 做為保存。If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. 如果工作流程已建立但尚未保存,則必須在呼叫這個方法之前設定 InstanceStore,否則呼叫這個方法時會擲回 InvalidOperationExceptionIf the workflow was created and has not yet been persisted, then an InstanceStore must be configured before calling this method or else an InvalidOperationException is thrown when this method is called.

Unload(TimeSpan)

保存與卸載使用指定逾時間隔的工作流程執行個體。Persists and unloads a workflow instance using the specified time-out interval.

public:
 void Unload(TimeSpan timeout);
public void Unload (TimeSpan timeout);
member this.Unload : TimeSpan -> unit
Public Sub Unload (timeout As TimeSpan)

參數

timeout
TimeSpan

卸載作業必須在作業取消並擲回 TimeoutException 前完成的間隔。The interval in which the unload operation must complete before the operation is canceled and a TimeoutException is thrown.

範例

下列程式碼範例是NoPersistScope 活動範例的一部分。The following code example is part of the NoPersistScope Activity sample. 在這個範例中,工作流程已閒置而且主應用程式正等候使用者輸入。In this example, the workflow is idle and the host application is waiting for user input. 如果使用者選擇卸載,就會呼叫 UnloadIf the user chooses to unload, Unload is called. 如果呼叫成功,就會保存工作流程並從記憶體中卸載工作流程。If successful, the workflow is persisted and unloaded from memory.

// single interaction with the user. The user enters a string in the console and that
// string is used to resume the ReadLine activity bookmark
static void Interact(WorkflowApplication application, AutoResetEvent resetEvent)
{
    Console.WriteLine("Workflow is ready for input");
    Console.WriteLine("Special commands: 'unload', 'exit'");

    bool done = false;
    while (!done)
    {
        Console.Write("> ");
        string s = Console.ReadLine();
        if (s.Equals("unload"))
        {
            try
            {
                // attempt to unload will fail if the workflow is idle within a NoPersistZone
                application.Unload(TimeSpan.FromSeconds(5));
                done = true;
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        else if (s.Equals("exit"))
        {
            application.ResumeBookmark("inputBookmark", s);
            done = true;
        }
        else
        {
            application.ResumeBookmark("inputBookmark", s);
        }
    }
    resetEvent.WaitOne();
}

備註

如果先前已從持續性載入工作流程執行個體,則會使用用來載入工作流程的相同 InstanceStore 做為保存。If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. 如果工作流程已建立但尚未保存,則必須在呼叫這個方法之前設定 InstanceStore,否則呼叫這個方法時會擲回 InvalidOperationExceptionIf the workflow was created and has not yet been persisted, then an InstanceStore must be configured before calling this method or else an InvalidOperationException is thrown when this method is called.

Unload()

保存或卸載工作流程執行個體。Persists and unloads a workflow instance.

public:
 void Unload();
public void Unload ();
member this.Unload : unit -> unit
Public Sub Unload ()

範例

下列程式碼範例是NoPersistScope 活動範例的一部分。The following code example is part of the NoPersistScope Activity sample. 在這個範例中,工作流程已閒置而且主應用程式正等候使用者輸入。In this example, the workflow is idle and the host application is waiting for user input. 如果使用者選擇卸載,就會呼叫 UnloadIf the user chooses to unload, Unload is called. 如果呼叫成功,就會保存工作流程並從記憶體中卸載工作流程。If successful, the workflow is persisted and unloaded from memory.

// single interaction with the user. The user enters a string in the console and that
// string is used to resume the ReadLine activity bookmark
static void Interact(WorkflowApplication application, AutoResetEvent resetEvent)
{
    Console.WriteLine("Workflow is ready for input");
    Console.WriteLine("Special commands: 'unload', 'exit'");

    bool done = false;
    while (!done)
    {
        Console.Write("> ");
        string s = Console.ReadLine();
        if (s.Equals("unload"))
        {
            try
            {
                // attempt to unload will fail if the workflow is idle within a NoPersistZone
                application.Unload(TimeSpan.FromSeconds(5));
                done = true;
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        else if (s.Equals("exit"))
        {
            application.ResumeBookmark("inputBookmark", s);
            done = true;
        }
        else
        {
            application.ResumeBookmark("inputBookmark", s);
        }
    }
    resetEvent.WaitOne();
}

備註

根據預設,卸載作業必須在 30 秒內完成,否則會擲回 TimeoutExceptionBy default, the unload operation must complete in 30 seconds or a TimeoutException is thrown.

如果先前已從持續性載入工作流程執行個體,則會使用用來載入工作流程的相同 InstanceStore 做為保存。If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. 如果工作流程已建立但尚未保存,則必須在呼叫這個方法之前設定 InstanceStore,否則呼叫這個方法時會擲回 InvalidOperationExceptionIf the workflow was created and has not yet been persisted, then an InstanceStore must be configured before calling this method or else an InvalidOperationException is thrown when this method is called.

適用於