DispatcherQueue.TryEnqueue Método

Definición

Sobrecargas

TryEnqueue(DispatcherQueueHandler)

Agrega una tarea a DispatcherQueue que se ejecutará en el subproceso asociado a DispatcherQueue.

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

Agrega una tarea a DispatcherQueue que se ejecutará en el subproceso asociado a DispatcherQueue con la prioridad especificada.

TryEnqueue(DispatcherQueueHandler)

Agrega una tarea a DispatcherQueue que se ejecutará en el subproceso asociado a DispatcherQueue.

public:
 virtual bool TryEnqueue(DispatcherQueueHandler ^ callback) = TryEnqueue;
[Windows.Foundation.Metadata.Overload("TryEnqueue")]
public bool TryEnqueue(DispatcherQueueHandler callback);
function tryEnqueue(callback)
Public Function TryEnqueue (callback As DispatcherQueueHandler) As Boolean

Parámetros

callback
DispatcherQueueHandler

Delegado de la tarea que se va a ejecutar.

Devoluciones

Boolean

bool

True si la tarea se agregó a la cola. De lo contrario, se devuelve el valor False.

Atributos

Ejemplos

En el ejemplo siguiente se muestra cómo crear un subproceso e inicializar un dispatcherQueueController y ejecutar un bucle de eventos DispatcherQueue en él.

// Create a new thread and initialize a DispatcherQueueController
// and run a DispatcherQueue event loop on it.
_queueController =
    DispatcherQueueController.CreateOnDedicatedThread();
_queue = _queueController.DispatcherQueue;

// This is the first TryEnqueue() after creating the DispatcherQueue. The
// first TryEnqueue task is guaranteed to be invoked first on the new
// thread.
bool isQueued = _queue.TryEnqueue(
        () =>
        {
            // task to perform on another thread.
        });

Comentarios

La cola invocará la devolución de llamada en serie.

Una vez que se haya llamado a ShutdownQueueAsync(), la cola no pondrá en cola nuevas tareas y este método devolverá false.

Se aplica a

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

Agrega una tarea a DispatcherQueue que se ejecutará en el subproceso asociado a DispatcherQueue con la prioridad especificada.

public:
 virtual bool TryEnqueue(DispatcherQueuePriority priority, DispatcherQueueHandler ^ callback) = TryEnqueue;
[Windows.Foundation.Metadata.Overload("TryEnqueueWithPriority")]
public bool TryEnqueue(DispatcherQueuePriority priority, DispatcherQueueHandler callback);
function tryEnqueue(priority, callback)
Public Function TryEnqueue (priority As DispatcherQueuePriority, callback As DispatcherQueueHandler) As Boolean

Parámetros

priority
DispatcherQueuePriority

Prioridad de la tarea (por ejemplo, Baja, Normal o Alta).

callback
DispatcherQueueHandler

Delegado de la tarea que se va a ejecutar.

Devoluciones

Boolean

bool

True si la tarea se agregó a la cola. De lo contrario, se devuelve el valor False.

Atributos

Ejemplos

En el ejemplo siguiente se muestra cómo crear un subproceso e inicializar un dispatcherQueueController y ejecutar un bucle de eventos DispatcherQueue en él.

// Create a new thread and initialize a DispatcherQueueController
// and run a DispatcherQueue event loop on it.
_queueController =
    DispatcherQueueController.CreateOnDedicatedThread();
_queue = _queueController.DispatcherQueue;

// This is the first TryEnqueue() after creating the DispatcherQueue. The
// first TryEnqueue task is guaranteed to be invoked first on the new
// thread, regardless of what priority it was enqueued at.
bool isQueued = _queue.TryEnqueue(Windows.System.DispatcherQueuePriority.High,
        () =>
        {
            // task to perform on another thread.
        });

Comentarios

La cola invocará la devolución de llamada en serie y en orden de prioridad.

Una vez que se haya llamado a ShutdownQueueAsync(), la cola no pondrá en cola nuevas tareas y este método devolverá false.

Se aplica a