共用方式為


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

適用於