This documentation is archived and is not being maintained.

WorkflowInstance.Unload Method

Unloads the workflow instance from memory to the persistence store. This call will block 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)

public void Unload ()
public void Unload ()
public function Unload ()
Not applicable.

Exception typeCondition


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

Unload is synchronous; that is, it returns after completing any action that it performs. If the workflow instance is not idle, then 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, then 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.

The following example demonstrates calling Unload on a WorkflowInstance object.

// 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
// Create a WorkflowInstance object
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(IdleWorkflow));
// Start the workflow instance
//Unload the instance

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0