Share 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 com a prioridade especificada.

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")]
public bool TryEnqueue(DispatcherQueueHandler callback);
function tryEnqueue(callback)
Public Function TryEnqueue (callback As DispatcherQueueHandler) As Boolean

Parâmetros

callback
DispatcherQueueHandler

Um delegado para a tarefa a ser executada.

Retornos

Boolean

bool

True se a tarefa foi adicionada à fila. Caso contrário, false.

Atributos

Exemplos

O exemplo a seguir mostra como criar um novo thread e inicializar um DispatcherQueueController e executar um loop de evento DispatcherQueue nele.

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

Comentários

A fila invocará o retorno de chamada serialmente.

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 com a prioridade 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

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

callback
DispatcherQueueHandler

Um delegado para a tarefa a ser executada.

Retornos

Boolean

bool

True se a tarefa foi adicionada à fila. Caso contrário, false.

Atributos

Exemplos

O exemplo a seguir mostra como criar um novo thread e inicializar um DispatcherQueueController e executar um loop de evento DispatcherQueue nele.

// 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 serialmente e em 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