DispatcherQueue
DispatcherQueue
DispatcherQueue
DispatcherQueue
Class
Definition
Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Prerelease APIs are identified by a Prerelease label.
[Contains prerelease APIs.]
Manages a prioritized queue on which tasks execute in a serial fashion on a thread.
public : sealed class DispatcherQueue : IDispatcherQueuepublic sealed class DispatcherQueue : IDispatcherQueuePublic NotInheritable Class DispatcherQueue Implements IDispatcherQueue// This API is not available in Javascript.
- Attributes
| Device family |
Windows 10 Insider Preview (introduced v10.0.16257.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v5)
|
Remarks
All tasks dispatched to a queue execute on the same thread.
Methods
CreateTimer() CreateTimer() CreateTimer() CreateTimer()
Prerelease. Creates a DispatcherQueueTimer on the DispatcherQueue to execute a task periodically after a time interval has elapsed.
public : DispatcherQueueTimer CreateTimer()public DispatcherQueueTimer CreateTimer()Public Function CreateTimer() As DispatcherQueueTimer// This API is not available in Javascript.
An DispatcherQueueTimer that can queue tasks on a timed basis to the current DispatcherQueue.
Remarks
By default, a repeating timer is created. Set IsRepeating to false to make it non-repeating.
GetForCurrentThread() GetForCurrentThread() GetForCurrentThread() GetForCurrentThread()
Prerelease. Gets the DispatcherQueue associated with the current thread.
public : static DispatcherQueue GetForCurrentThread()public static DispatcherQueue GetForCurrentThread()Public Static Function GetForCurrentThread() As DispatcherQueue// This API is not available in Javascript.
A DispatcherQueue instance that will execute tasks serially on the current thread.
TryEnqueue(DispatcherQueueHandler) TryEnqueue(DispatcherQueueHandler) TryEnqueue(DispatcherQueueHandler) TryEnqueue(DispatcherQueueHandler)
Prerelease. Adds a task to the DispatcherQueue which will be executed on the thread associated with the DispatcherQueue.
public : PlatForm::Boolean TryEnqueue(DispatcherQueueHandler callback)public bool TryEnqueue(DispatcherQueueHandler callback)Public Function TryEnqueue(callback As DispatcherQueueHandler) As bool// This API is not available in Javascript.
- callback
- DispatcherQueueHandler DispatcherQueueHandler DispatcherQueueHandler DispatcherQueueHandler
The task to execute.
True indicates that the task was added to the queue; false, otherwise.
Examples
// 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.
});
Remarks
The task will be queued at Normal priority. The queue will invoke callback serially and in priority order.
Once ShutdownQueueAsync() has been called, the queue will not queue new tasks and this method will return false.
TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler) TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler) TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler) TryEnqueue(DispatcherQueuePriority, DispatcherQueueHandler)
Prerelease. Adds a task to the DispatcherQueue which will be executed on the thread associated with the DispatcherQueue.
public : PlatForm::Boolean TryEnqueue(DispatcherQueuePriority priority, DispatcherQueueHandler callback)public bool TryEnqueue(DispatcherQueuePriority priority, DispatcherQueueHandler callback)Public Function TryEnqueue(priority As DispatcherQueuePriority, callback As DispatcherQueueHandler) As bool// This API is not available in Javascript.
- priority
- DispatcherQueuePriority DispatcherQueuePriority DispatcherQueuePriority DispatcherQueuePriority
The priority of the task such as Low, Normal, or High.
- callback
- DispatcherQueueHandler DispatcherQueueHandler DispatcherQueueHandler DispatcherQueueHandler
A delegate to the task to execute.
True indicates that the task was added to the queue; false, otherwise.
Examples
// 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.
});
Remarks
The queue will invoke callback serially and in priority order.
Once ShutdownQueueAsync() has been called, the queue will not queue new tasks and this method will return false.
Events
ShutdownCompleted ShutdownCompleted ShutdownCompleted ShutdownCompleted
Prerelease. Fires after the DispatcherQueue event loop stops which is the last step in the DispatcherQueue shutdown process.
public : event TypedEventHandler ShutdownCompleted<DispatcherQueue, object>public event TypedEventHandler ShutdownCompleted<DispatcherQueue, object>Public Event ShutdownCompleted<DispatcherQueue, object>// This API is not available in Javascript.
Examples
// Invoked after the DispatcherQueue event loop exits.
_dispatcherQueue.ShutdownCompleted += (s, e) =>
{
// clean up state
};
Remarks
The event is fired on the thread running the DispatcherQueue event loop. After this event is fired, any work posted to the DispatcherQueue will not be scheduled.
ShutdownStarting ShutdownStarting ShutdownStarting ShutdownStarting
Prerelease. Fires before the dispatcher queue initiates an exit from its event loop.
public : event TypedEventHandler ShutdownStarting<DispatcherQueue, DispatcherQueueShutdownStartingEventArgs>public event TypedEventHandler ShutdownStarting<DispatcherQueue, DispatcherQueueShutdownStartingEventArgs>Public Event ShutdownStarting<DispatcherQueue, DispatcherQueueShutdownStartingEventArgs>// This API is not available in Javascript.
Examples
_dispatcherQueue.ShutdownStarting += (s, e) =>
{
// Queue is shutting down, do this last operation to
// update state before the dispatcher loop exits
_queue.TryEnqueue(
() =>
{
// clean up state
});
};
Remarks
The event is fired on the thread running the DispatcherQueue event loop.
This event fires before the DispatcherQueue initiates the exit from the event loop. Event handlers for this event can queue work from within the handler. The event handler can take a deferral and continue to post work to the DispatcherQueue until the deferral completes. Once the deferral completes, no new work will be accepted by the DispatcherQueue.