Язык

DispatcherQueue.TryEnqueue Метод

Определение

Перегрузки

Имя Описание
TryEnqueue(DispatcherQueueHandler)

Добавляет задачу в dispatcherQueue , которая будет выполняться в потоке, связанном с диспетчеромQueue.

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

Добавляет задачу в диспетчеркуQueue , которая будет выполняться в потоке, связанном с диспетчеромQueue с указанным приоритетом.

TryEnqueue(DispatcherQueueHandler)

Добавляет задачу в dispatcherQueue , которая будет выполняться в потоке, связанном с ДиспетчеромQueue.

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

Параметры

callback
DispatcherQueueHandler

Делегат для выполнения задачи.

Возвращаемое значение

Boolean

bool

Значение True , если задача была добавлена в очередь. В противном случае — false.

Атрибуты

Примеры

В следующем примере показано, как создать новый поток и инициализировать диспетчерQueueController и запустить цикл событий DispatcherQueue на нем.

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

Комментарии

Очередь будет вызывать обратный вызов последовательно.

После вызова ShutdownQueueAsync() очередь не будет очереди новых задач, и этот метод вернет false.

Применяется к

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

Добавляет задачу в диспетчеркуQueue , которая будет выполняться в потоке, связанном с диспетчеромQueue с указанным приоритетом.

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

Параметры

priority
DispatcherQueuePriority

Приоритет задачи (например, "Низкий", "Обычный" или "Высокий").

callback
DispatcherQueueHandler

Делегат для выполнения задачи.

Возвращаемое значение

Boolean

bool

Значение True , если задача была добавлена в очередь. В противном случае — false.

Атрибуты

Примеры

В следующем примере показано, как создать новый поток и инициализировать диспетчерQueueController и запустить цикл событий DispatcherQueue на нем.

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

Комментарии

Очередь будет вызывать обратный вызов последовательно и в порядке приоритета.

После вызова ShutdownQueueAsync() очередь не будет очереди новых задач, и этот метод вернет false.

Применяется к