Partilhar via


DispatcherQueue.TryEnqueue Método

Definição

Sobrecargas

TryEnqueue(DispatcherQueueHandler)

Adiciona uma tarefa ao DispatcherQueue que será executada no thread associado ao DispatcherQueue.

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

Adiciona uma tarefa ao DispatcherQueue que será executada no thread associado ao DispatcherQueue.

TryEnqueue(DispatcherQueueHandler)

Adiciona uma tarefa ao DispatcherQueue que será executada no thread associado ao DispatcherQueue.

public:
 virtual bool TryEnqueue(DispatcherQueueHandler ^ callback) = TryEnqueue;
/// [Windows.Foundation.Metadata.Overload("TryEnqueue")]
bool TryEnqueue(DispatcherQueueHandler const& callback);
[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

A tarefa a ser executada.

Retornos

Boolean

bool

True indica que a tarefa foi adicionada à fila; false, caso contrário.

Atributos

Exemplos

// 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 callback is guaranteed to be invoked first despite Priority on the
// newly created thread.

bool isQueued = _queue.TryEnqueue(
        () =>
        {
            // task to perform on another thread.
        });

Comentários

A tarefa será enfileirada em Prioridade normal . A fila invocará o retorno de chamada em série e na ordem de prioridade.

Depois que ShutdownQueueAsync() tiver sido chamado, a fila não enfileirará novas tarefas e esse método retornará false.

Aplica-se a

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

Adiciona uma tarefa ao DispatcherQueue que será executada no thread associado ao DispatcherQueue.

public:
 virtual bool TryEnqueue(DispatcherQueuePriority priority, DispatcherQueueHandler ^ callback) = TryEnqueue;
/// [Windows.Foundation.Metadata.Overload("TryEnqueueWithPriority")]
bool TryEnqueue(DispatcherQueuePriority const& priority, DispatcherQueueHandler const& callback);
[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

A prioridade da tarefa, como Baixa, Normal ou Alta.

callback
DispatcherQueueHandler

Um delegado para a tarefa a ser executada.

Retornos

Boolean

bool

True indica que a tarefa foi adicionada à fila; false, caso contrário.

Atributos

Exemplos

// 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.
        });

Comentários

A fila invocará o retorno de chamada em série e na ordem de prioridade.

Depois que ShutdownQueueAsync() tiver sido chamado, a fila não enfileirará novas tarefas e esse método retornará false.

Aplica-se a