DispatcherQueue.TryEnqueue 方法

定义

重载

TryEnqueue(DispatcherQueueHandler)

将任务添加到 DispatcherQueue ,该任务将在与 DispatcherQueue 关联的线程上执行。

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

将任务添加到 DispatcherQueue ,该任务将在与 DispatcherQueue 关联的线程上执行。

TryEnqueue(DispatcherQueueHandler)

将任务添加到 DispatcherQueue ,该任务将在与 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

参数

callback
DispatcherQueueHandler

要执行的任务。

返回

Boolean

bool

True 表示任务已添加到队列中; 否则为 false

属性

示例

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

注解

任务将以 普通 优先级排队。 队列将按优先级顺序串行调用 回调

调用 ShutdownQueueAsync () 后,队列不会对新任务进行排队,此方法将返回 false

适用于

TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)

将任务添加到 DispatcherQueue ,该任务将在与 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

参数

priority
DispatcherQueuePriority

任务的优先级,例如“低”、“普通”或“高”。

callback
DispatcherQueueHandler

对要执行的任务的委托。

返回

Boolean

bool

True 表示任务已添加到队列中; 否则为 false

属性

示例

// 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

适用于