Share via


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

매개 변수

callback
DispatcherQueueHandler

실행할 태스크에 대한 대리자입니다.

반환

Boolean

bool

True 이면 작업이 큐에 추가되었습니다. 그렇지 않으면 false입니다.

특성

예제

다음 예제에서는 새 스레드를 만들고 DispatcherQueueController 를 초기화하고 해당 스레드에서 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)

DispatcherQueue와 연결된 스레드에서 지정된 우선 순위로 실행되는 작업을 DispatcherQueue에 추가합니다.

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입니다.

특성

예제

다음 예제에서는 새 스레드를 만들고 DispatcherQueueController 를 초기화하고 해당 스레드에서 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를 반환합니다.

적용 대상