WorkflowInstance.Unload 方法
定义
将工作流实例从内存卸载到持久性存储区。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.
public:
void Unload();
public void Unload ();
member this.Unload : unit -> unit
Public Sub Unload ()
例外
不存在已注册到工作流运行时引擎的持久性服务。There is no persistence service registered with the workflow runtime engine.
示例
下面的示例演示对 Unload 对象调用 WorkflowInstance。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
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 是同步的,也就是说,它将在完成其执行的任何操作之后返回。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. 只有当前计划的工作项完成之后,才可以中断实例,这种情况通常发生在当前运行的活动从其 Execute 方法返回时。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. 但是,如果实例正在执行 TransactionScopeActivity,则事务范围必须在可将实例中断之前完成执行。However, if the instance is executing a TransactionScopeActivity, the transaction scope must complete execution before the instance can be interrupted. 然后,“Unload”将使用持久性服务从内存中移除工作流实例,并将其保留在数据存储区。Unload then uses the persistence service to remove the workflow instance from memory and persists it to a data store. 如果不存在使用 WorkflowRuntime 注册的持久性服务,则 Unload 将引发 InvalidOperationException。If there is no persistence service registered with the WorkflowRuntime, Unload throws an InvalidOperationException. 如果工作流实例成功保留,则运行时将引发 WorkflowUnloaded 事件。If the workflow instance is successfully persisted, the runtime raises the WorkflowUnloaded event.
宿主可以使用 Unload 回收空闲工作流的系统资源。The host can use Unload to reclaim system resources from an idle workflow.