Share via


WorkflowInstance.Unload Metodo

Definizione

Scarica l'istanza del flusso di lavoro dalla memoria all'archivio di persistenza. Questa chiamata rimane bloccata fino al termine del lavoro attualmente pianificato o alla fine di un ambito della transazione.

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

Eccezioni

Nessun servizio di persistenza è registrato nel motore di runtime del flusso di lavoro.

Esempio

Nell'esempio seguente viene illustrato come chiamare Unload su un oggetto 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()

Commenti

Il metodo Unload è sincrono; ovvero viene restituito dopo il completamento delle azioni eseguite. Se l'istanza del flusso di lavoro non è inattiva, il runtime attende fino a quando l'istanza può essere interrotta. Un'istanza può essere interrotta solo dopo che l'elemento di lavoro attualmente pianificato viene completato. In genere ciò avviene quando l'attività attualmente in esecuzione viene restituita dal metodo Execute. Tuttavia, se l'istanza sta eseguendo un oggetto TransactionScopeActivity, l'esecuzione dell'ambito della transazione deve essere completata prima che l'istanza possa essere interrotta. Unload utilizza quindi il servizio di persistenza per rimuovere l'istanza del flusso di lavoro dalla memoria e lo rende persistente in un archivio dati. Se nessun servizio di persistenza è registrato con WorkflowRuntime, Unload genera un'eccezione InvalidOperationException. Se l'istanza del flusso di lavoro è stata resa persistente, il runtime genera l'evento WorkflowUnloaded.

L'host può utilizzare il metodo Unload per recuperare risorse di sistema da un flusso di lavoro inattivo.

Si applica a