WorkflowApplication.Persist 方法

定義

將工作流程執行個體保存到執行個體存放區。Persists a workflow instance to an instance store.

多載

Persist()

將工作流程執行個體保存到執行個體存放區。Persists a workflow instance to an instance store.

Persist(TimeSpan)

使用指定逾時間隔,將工作流程執行個體保存到執行個體存放區。Persists a workflow instance to an instance store using the specified time-out interval.

備註

如果先前已從持續性載入工作流程執行個體,則會使用用來載入工作流程的相同 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.

Persist()

將工作流程執行個體保存到執行個體存放區。Persists a workflow instance to an instance store.

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

範例

下列範例會呼叫 Persist,以便在工作流程啟動之前保存工作流程執行個體。The following example calls Persist to persist a workflow instance before the workflow is started. 這個範例是StartAndUnloadInstance 保存工作流程應用程式範例中方法的一部分。This example is part of the StartAndUnloadInstance method in the Persisting a Workflow Application sample.

WorkflowApplication application = new WorkflowApplication(activity);

application.InstanceStore = instanceStore;

//returning IdleAction.Unload instructs the WorkflowApplication to persists application state and remove it from memory  
application.PersistableIdle = (e) =>
{
    return PersistableIdleAction.Unload;
};

application.Unloaded = (e) =>
{
    instanceUnloaded.Set();
};

//This call is not required 
//Calling persist here captures the application durably before it has been started
application.Persist();
id = application.Id;
application.Run();

instanceUnloaded.WaitOne();

備註

如果保存作業沒有在 30 秒內完成,則會擲回 TimeoutExceptionIf the persist operation does not complete within 30 seconds, 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.

Persist(TimeSpan)

使用指定逾時間隔,將工作流程執行個體保存到執行個體存放區。Persists a workflow instance to an instance store using the specified time-out interval.

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

參數

timeout
TimeSpan

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

範例

下列範例會呼叫 Persist,以便在工作流程啟動之前保存工作流程執行個體。The following example calls Persist to persist a workflow instance before the workflow is started. 這個範例來自StartAndUnloadInstance 保存工作流程應用程式範例中的方法。This example is from the StartAndUnloadInstance method in the Persisting a Workflow Application sample.

WorkflowApplication application = new WorkflowApplication(activity);

application.InstanceStore = instanceStore;

//returning IdleAction.Unload instructs the WorkflowApplication to persists application state and remove it from memory  
application.PersistableIdle = (e) =>
{
    return PersistableIdleAction.Unload;
};

application.Unloaded = (e) =>
{
    instanceUnloaded.Set();
};

//This call is not required 
//Calling persist here captures the application durably before it has been started
application.Persist();
id = application.Id;
application.Run();

instanceUnloaded.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.

適用於