.NET Framework Class Library
WorkflowInstance..::.Unload Method

Unloads the workflow instance from memory to the persistence store. This call blocks until after the currently scheduled work is finished, or the end of a transaction scope.

Namespace:  System.Workflow.Runtime
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)
Syntax

Visual Basic (Declaration)
Public Sub Unload
Visual Basic (Usage)
Dim instance As WorkflowInstance

instance.Unload()
C#
public void Unload()
Visual C++
public:
void Unload()
JScript
public function Unload()
Exceptions

ExceptionCondition
InvalidOperationException

There is no persistence service registered with the workflow runtime engine.

Remarks

Unload is synchronous; that is, it returns after completing any action that it performs. If the workflow instance is not idle, the runtime waits until the instance can be interrupted. An instance can only be interrupted after the currently scheduled work item completes; this is typically when the currently running Activity returns from its Execute method. However, if the instance is executing a TransactionScopeActivity, the transaction scope must complete execution before the instance can be interrupted. Unload then uses the persistence service to remove the workflow instance from memory and persists it to a data store. If there is no persistence service registered with the WorkflowRuntime, Unload throws an InvalidOperationException. If the workflow instance is successfully persisted, the runtime raises the WorkflowUnloaded event.

The host can use Unload to reclaim system resources from an idle workflow.

Examples

The following example demonstrates calling Unload on a WorkflowInstance object.

Visual Basic
' Create a WorkflowRuntime object
Dim workflowRuntime As New WorkflowRuntime()
' Create a new instance of the out-of-box SqlWorkflowPersistenceService
Dim persistenceService As _
   New SqlWorkflowPersistenceService( _
   "Initial Catalog=SqlPersistenceServiceData Source=localhostIntegrated Security=SSPI")
' Add the service to the runtime
workflowRuntime.AddService(persistenceService)
' Create a WorkflowInstance object
Dim workflowInstance As WorkflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1))
' Start the workflow instance
workflowInstance.Start()
'Unload the instance
workflowInstance.Unload()
C#
// Create a WorkflowRuntime object
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
// Create a new instance of the out-of-box SqlWorkflowPersistenceService
SqlWorkflowPersistenceService persistenceService =
   new SqlWorkflowPersistenceService(
   "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;");
// Add the service to the runtime
workflowRuntime.AddService(persistenceService);
// Create a WorkflowInstance object
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(Workflow1));
// Start the workflow instance
workflowInstance.Start();
//Unload the instance
workflowInstance.Unload();
.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Tags :


Page view tracker