WorkflowInstance.EnqueueItemOnIdle(IComparable, Object, IPendingWork, Object) Método
Definição
Posta uma mensagem na fila de fluxo de trabalho especificada quando o fluxo de trabalho está ocioso.Posts a message to the specified workflow queue when the workflow is idle. EnqueueItemOnIdle(IComparable, Object, IPendingWork, Object) espera até que o fluxo de trabalho atinja um ponto de ociosidade e seja enfileirado depois de verificar se o agendador de fluxo de trabalho está ocioso (ou seja, se nenhuma operação ativa está sendo executada).EnqueueItemOnIdle(IComparable, Object, IPendingWork, Object) waits until the workflow reaches an idle point and enqueues after verifying that the workflow scheduler is idle (that is, no active operation is being executed).
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)
Parâmetros
- queueName
- IComparable
O nome do WorkflowQueue.The name of the WorkflowQueue.
- item
- Object
O objeto a ser enfileirado.The object to enqueue.
- pendingWork
- IPendingWork
Um IPendingWork que permite que o remetente seja notificado quando um item for entregue.An IPendingWork that allows the sender to be notified when item is delivered.
- workItem
- Object
Um objeto a ser passado para os métodos IPendingWork.An object to be passed to the IPendingWork methods.
Exceções
queueName é uma referência nula (Nothing no Visual Basic).queueName is a null reference (Nothing in Visual Basic).
O mecanismo de runtime de fluxo de trabalho não está em execução.The workflow runtime engine is not running.
- ou --or- A instância de fluxo de trabalho é suspensa.The workflow instance is suspended.
- ou --or-
A WorkflowQueue especificada por queueName não existe.The WorkflowQueue specified by queueName does not exist.
- ou --or-
A WorkflowQueue especificada por queueName não está habilitada.The WorkflowQueue specified by queueName is not enabled.
Exemplos
O exemplo a seguir demonstra o envio de informações para uma instância de fluxo de trabalho usando o EnqueueItemOnIdle método.The following example demonstrates sending information to a workflow instance using the EnqueueItemOnIdle method. Primeiro, um objeto WorkflowInstance é criado e iniciado; em seguida, um objeto que implementa a IPendingWork interface é criado.First, a WorkflowInstance object is created and started; next, an object that implements the IPendingWork interface is created. EnqueueItemOnIdle em seguida, é chamado, passando valores de cadeia de caracteres para o nome da fila, o item enfileirado e o item de trabalho a ser passado para os métodos do objeto de pendência.EnqueueItemOnIdle is then called, passing in string values for the queue name, the enqueued item, and the work item to be passed to the methods of the pendingWork object.
// 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")
Comentários
Aguarda a instância do fluxo de trabalho ficar ociosa e, em seguida, envia o item para o especificado WorkflowQueue .Waits for the workflow instance to become idle and then sends the item to the specified WorkflowQueue. Se você chamar EnqueueItemOnIdle enquanto a instância do fluxo de trabalho é suspensa, o mecanismo de tempo de execução do fluxo de trabalho gerará um InvalidOperationException .If you call EnqueueItemOnIdle while the workflow instance is suspended, the workflow runtime engine will throw an InvalidOperationException. Se você quiser ser notificado quando a mensagem for entregue, poderá implementar IPendingWork em seu serviço e passar um workItem IPendingWork objeto e para EnqueueItem .If you want to be notified when the message is delivered, you can implement IPendingWork in your service and pass a workItem and an IPendingWork object to EnqueueItem. Se você não quiser essa notificação, poderá passar uma referência nula ( Nothing em Visual Basic) para pendingWork e workItem .If you do not want such notification, you can pass a null reference (Nothing in Visual Basic) for pendingWork and workItem.
Ao usar esse método com um fluxo de trabalho de máquina de estado, você pode receber uma exceção que contém a mensagem "a fila" {0} não está habilitada. "When you are using this method with a state machine workflow, you might get an exception that contains the message "Queue '{0}' is not enabled." Isso ocorre quando o estado atual da máquina de estado não sabe como lidar com um evento específico.This occurs when the current state of the state machine does not know how to handle a specific event. Por exemplo, quando algum estado que não seja o estado atual contiver o EventDrivenActivity que contém o HandleExternalEventActivity que é representado pela fila ' {0} '.For example, when some state other than the current state contains the EventDrivenActivity that contains the HandleExternalEventActivity that is represented by the queue '{0}'.