편집

다음을 통해 공유


WorkflowPersistenceService.LoadWorkflowInstanceState(Guid) Method

Definition

When implemented in a derived class, loads the specified state of the workflow instance back into memory.

protected public:
 abstract System::Workflow::ComponentModel::Activity ^ LoadWorkflowInstanceState(Guid instanceId);
protected internal abstract System.Workflow.ComponentModel.Activity LoadWorkflowInstanceState (Guid instanceId);
abstract member LoadWorkflowInstanceState : Guid -> System.Workflow.ComponentModel.Activity
Protected Friend MustOverride Function LoadWorkflowInstanceState (instanceId As Guid) As Activity

Parameters

instanceId
Guid

The Guid of the root activity of the workflow instance.

Returns

An Activity that represents the root activity of the workflow instance.

Examples

The following example demonstrates an implementation of the LoadWorkflowInstanceState method. This example is from the Custom Persistence Service sample, from the FilePersistenceService.cs file. For more information, see Custom Persistence Service Sample.

// Load workflow instance state.
protected override Activity LoadWorkflowInstanceState(Guid instanceId)
{
    Console.WriteLine("Loading instance: {0}\n", instanceId);
    byte[] workflowBytes = DeserializeFromFile(instanceId);
    return WorkflowPersistenceService.RestoreFromDefaultSerializedForm(workflowBytes, null);
}
' Load workflow instance state.
Protected Overrides Function LoadWorkflowInstanceState(ByVal instanceId As System.Guid) As System.Workflow.ComponentModel.Activity
    Console.WriteLine("Loading instance: 0}" + vbLf, instanceId)
    Dim obj As Object = DeserializeFromFile(instanceId)
    Dim workflowBytes As Byte() = DeserializeFromFile(instanceId)
    Return WorkflowPersistenceService.RestoreFromDefaultSerializedForm(workflowBytes, Nothing)
End Function

Remarks

You must restore an identical copy of the activity. To do this, you must restore a valid Stream from your representation of the workflow instance in the data store; then you must pass this Stream to one of the overloaded Load methods to deserialize the workflow instance state. If your persistence service cannot load the workflow instance state from its data store, it should throw a PersistenceException with an appropriate message.

The workflow runtime engine implements locking semantics to restrict access to a workflow instance state that is saved in a data store. This can be accessed by persistence services that run in multiple processes. The locking semantics are designed to prevent persistence services that run in two different processes from loading the same workflow instance into memory at the same time. Depending on the type of environment that your persistence service is designed to support, you may choose whether to support this functionality. If you choose to support the runtime locking semantics, and if this workflow instance state has been previously locked by another process, then you should throw a WorkflowOwnershipException. Otherwise, you should lock access to the workflow instance state in your data store. The workflow instance state can be unlocked by a call to UnlockWorkflowInstanceState or a call to SaveWorkflowInstanceState with the unlock parameter set to true.

Applies to