Share via


WorkflowInstance.EnqueueItemOnIdle Metodo

Definizione

Inserisce un messaggio in modo sincrono nella coda del flusso di lavoro quando il flusso di lavoro è inattivo. EnqueueItemOnIdle(IComparable, Object, IPendingWork, Object) attende che il flusso di lavoro raggiunga un punto inattivo e lo inserisce in una coda dopo avere verificato che l'Utilità di pianificazione del flusso di lavoro sia inattiva (ovvero, nessuna operazione attiva è in esecuzione).

public:
 void EnqueueItemOnIdle(IComparable ^ queueName, System::Object ^ item, System::Workflow::Runtime::IPendingWork ^ pendingWork, System::Object ^ workItem);
public void EnqueueItemOnIdle (IComparable queueName, object item, System.Workflow.Runtime.IPendingWork pendingWork, object workItem);
member this.EnqueueItemOnIdle : IComparable * obj * System.Workflow.Runtime.IPendingWork * obj -> unit
Public Sub EnqueueItemOnIdle (queueName As IComparable, item As Object, pendingWork As IPendingWork, workItem As Object)

Parametri

queueName
IComparable

Nome di WorkflowQueue.

item
Object

Oggetto da accodare.

pendingWork
IPendingWork

Interfaccia IPendingWork che consente al mittente di ricevere una notifica quando item viene recapitato.

workItem
Object

Oggetto da passare ai metodi IPendingWork.

Eccezioni

queueName è un riferimento null (Nothing in Visual Basic).

Il motore di runtime del flusso di lavoro non è in esecuzione.

-oppure- L'istanza del flusso di lavoro è sospesa.

-oppure- La classe WorkflowQueue specificata da queueName non esiste.

-oppure- La classe WorkflowQueue specificata da queueName non è abilitata.

Esempio

Nell'esempio seguente viene illustrato l'invio di informazioni a un'istanza del flusso di lavoro utilizzando il metodo EnqueueItemOnIdle. Prima viene creato e avviato un oggetto WorkflowInstance; quindi viene creato un oggetto che implementa l'interfaccia IPendingWork. In seguito viene chiamato EnqueueItemOnIdle, passando valori stringa per il nome della coda, l'elemento accodato e l'elemento di lavoro da passare ai metodi dell'oggetto pendingWork.

// Create a workflow runtime environment
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
// Create a new instance of the out-of-box SqlWorkflowPersistenceService.
// Use the non-locking constructor, since we're only creating a single Workflow Runtime.
NameValueCollection parameters = new NameValueCollection();
parameters.Add("ConnectionString",
    "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;");
//Set UnloadOnIdle to true, so that the service will persist the workflow
parameters.Add("UnloadOnIdle", "true");
SqlWorkflowPersistenceService persistenceService =
   new SqlWorkflowPersistenceService(parameters);

// Add the service to the runtime
workflowRuntime.AddService(persistenceService);
// Create a WorkflowInstance object
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(Workflow1));
// Start the instance
workflowInstance.Start();
// Create an instance of a class that implements IPendingWork for notification
PendingService pendingWork = new PendingService();
// Send the workflow the message
workflowInstance.EnqueueItemOnIdle("ActionQueue", "StartWork", pendingWork, "ActionItem");
' Create a workflow runtime environment
Dim workflowRuntime As New WorkflowRuntime()
' Create a new instance of the out-of-box SqlWorkflowPersistenceService.
' Use the non-locking constructor, since we're only creating a single Workflow Runtime.
Dim parameters As New NameValueCollection()
parameters.Add("ConnectionString", _
    "Initial Catalog=SqlPersistenceServiceData Source=localhostIntegrated Security=SSPI")
'Set UnloadOnIdle to true, so that the service will persist the workflow
parameters.Add("UnloadOnIdle", "true")
Dim persistenceService As _
   New SqlWorkflowPersistenceService(parameters)

' Add the service to the runtime
workflowRuntime.AddService(persistenceService)
' Create a WorkflowInstance object
Dim workflowInstance As WorkflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1))
' Start the instance
workflowInstance.Start()
' Create an instance of a class that implements IPendingWork for notification
Dim pendingWork As New PendingService()
' Send the workflow the message
workflowInstance.EnqueueItemOnIdle("ActionQueue", "StartWork", pendingWork, "ActionItem")

Commenti

Aspetta che l'istanza del flusso di lavoro diventi inattiva e quindi invia l'oggetto item alla classe WorkflowQueue specificata. Se si chiama EnqueueItemOnIdle mentre l'istanza del flusso di lavoro è sospesa, il motore di runtime del flusso di lavoro genererà un'eccezione InvalidOperationException. Se si desidera ricevere una notifica quando il messaggio viene recapitato, è possibile implementare IPendingWork nel servizio e passare un workItem e un oggetto IPendingWork a EnqueueItem. Se non si desidera tale notifica, è possibile passare un riferimento null (Nothing in Visual Basic) per pendingWork e workItem.

Quando si usa questo metodo con un flusso di lavoro del computer di stato, è possibile che venga visualizzata un'eccezione che contiene il messaggio "Coda '{0}' non è abilitata". Ciò accade quando lo stato corrente della macchina a stati non sa come gestire un evento specifico. Ad esempio, quando uno stato diverso da quello corrente contiene la classe EventDrivenActivity che contiene l'oggetto HandleExternalEventActivity rappresentato dalla coda "{0}".

Si applica a