Share via


WorkflowInstance.Unload 方法

定义

将工作流实例从内存卸载到持久性存储区。 此调用将进行阻止,直至当前计划的工作完成或事务范围结束。

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

例外

不存在已注册到工作流运行时引擎的持久性服务。

示例

下面的示例演示对 Unload 对象调用 WorkflowInstance

// 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();
' 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()

注解

Unload 是同步的,也就是说,它将在完成其执行的任何操作之后返回。 如果工作流实例不处于空闲状态,则运行时将一直等待,直至可以中断实例。 只有当前计划的工作项完成之后,才可以中断实例,这种情况通常发生在当前运行的活动从其 Execute 方法返回时。 但是,如果实例正在执行 TransactionScopeActivity,则事务范围必须在可将实例中断之前完成执行。 然后,“Unload”将使用持久性服务从内存中移除工作流实例,并将其保留在数据存储区。 如果不存在使用 WorkflowRuntime 注册的持久性服务,则 Unload 将引发 InvalidOperationException。 如果工作流实例成功保留,则运行时将引发 WorkflowUnloaded 事件。

宿主可以使用 Unload 回收空闲工作流的系统资源。

适用于