WorkflowApplication.Persist Method

Definition

Persists a workflow instance to an instance store.

Overloads

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.

Remarks

If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. If 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.

C#
public void Persist();

Examples

The following example calls Persist to persist a workflow instance before the workflow is started.

C#
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();

Remarks

If the persist operation does not complete within 30 seconds, a TimeoutException is thrown.

If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. If 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.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Persist(TimeSpan)

Persists a workflow instance to an instance store using the specified time-out interval.

C#
public void Persist(TimeSpan timeout);

Parameters

timeout
TimeSpan

The interval in which the persist operation must complete before the operation is canceled and a TimeoutException is thrown.

Examples

The following example calls Persist to persist a workflow instance before the workflow is started.

C#
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();

Remarks

If the workflow instance was previously loaded from persistence, then the same InstanceStore used to load the workflow is used for persistence. If 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.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1