DispatchQueue DispatchQueue Class


Provides a task queue that can perform tasks either synchronously or asynchronously.

public sealed class DispatchQueue : CoreFoundation.DispatchObject
type DispatchQueue = class
    inherit DispatchObject


Queues are the fundamental mechanism for scheduling blocks for execution within the Apple Grand Central Dispatch framework.

All blocks submitted to dispatch queues are dequeued in FIFO order. By default, queues created with the default constructor wait for the previously dequeued block to complete before dequeuing the next block. This FIFO completion behavior is sometimes simply described as a "serial queue." Queues are not bound to any specific thread of execution and blocks submitted to independent queues may execute concurrently. Queues, like all dispatch objects, are reference counted and newly created queues have a reference count of one.

Concurrent dispatch queues are created by passing true as the value for the concurrent parameter on the constructor. Concurrent queues may invoke blocks concurrently (similarly to the global concurrent queues, but potentially with more overhead), and support barrier blocks submitted with the dispatch barrier API, which e.g. enables the implementation of efficient reader-writer schemes.

The optional label argument is used to describe the purpose of the queue and is useful during debugging and performance analysis. By convention, clients should pass a reverse DNS style label. If a label is provided, it is copied. If a label is not provided, then Label property returns an empty C string. For example:

      var my_queue = new DispatchQueue ("com.example.subsystem.taskXYZ");

Queues may be temporarily suspended and resumed with the functions Suspend() and Resume() respectively. Suspension is checked prior to block execution and is not preemptive.

Dispatch queue is T:System.Threading.SynchronizationContext aware and unless there is custom synchronization context set for the thread it will install its own synchronization context to ensure any context dispatch ends up on same dispatch queue.

Dispatch Barrier API

The dispatch barrier API is a mechanism for submitting barrier blocks to a dispatch queue, analogous to the DispatchAsync(Action)/DispatchSync(Action) methods. It enables the implementation of efficient reader/writer schemes. Barrier blocks only behave specially when submitted to concurrent queues ; on such a queue, a barrier block will not run until all blocks submitted to the queue earlier have completed, and any blocks submitted to the queue after a barrier block will not run until the barrier block has completed. When submitted to a a global queue or to a non-concurrent queue, barrier blocks behave identically to blocks submitted with the DispatchAsync(Action)/DispatchSync(Action) methods.


DispatchQueue(IntPtr) DispatchQueue(IntPtr)

Surfaces an unmanaged DispatchQueue as a managed object.

DispatchQueue(String) DispatchQueue(String)

Creates a named dispatch queue that serializes all submitted blocks.

DispatchQueue(String, Boolean) DispatchQueue(String, Boolean)

Creates a named dispatch queue that can optionally execute any submitted code concurrently.


Context Context

User defined context information attachech to a DispatchQueue.

CurrentQueue CurrentQueue

Developers should not use this deprecated property.

CurrentQueueLabel CurrentQueueLabel

Label for the current queue.

DefaultGlobalQueue DefaultGlobalQueue

Returns the default global queue, which is one of the built-in queues at the default priority.

Handle Handle

Handle (pointer) to the unmanaged object representation.

(Inherited from DispatchObject)
Label Label

Returns the label for this DispatchQueue.

MainQueue MainQueue

Returns the main global queue.


Check() Check() Inherited from DispatchObject
DispatchAfter(DispatchTime, Action) DispatchAfter(DispatchTime, Action)

Executes this time on or after the specified time.

DispatchAsync(Action) DispatchAsync(Action)
DispatchBarrierAsync(Action) DispatchBarrierAsync(Action)

Submits a barrier block for asynchronous execution on a dispatch queue

DispatchSync(Action) DispatchSync(Action)
Dispose() Dispose()

Releases the resources used by the DispatchObject object.

(Inherited from DispatchObject)
Dispose(Boolean) Dispose(Boolean)

Releases the resources used by the DispatchObject object.

(Inherited from DispatchObject)
Equals(Object) Equals(Object)
GetGlobalQueue(DispatchQueuePriority) GetGlobalQueue(DispatchQueuePriority)

Returns one of the global dispatch queues based on the requested priority.

GetHashCode() GetHashCode()
Resume() Resume()

Resumes execution of the queue.

SetTargetQueue(DispatchQueue) SetTargetQueue(DispatchQueue) Inherited from DispatchObject
Submit(Action<Int32>, Int64) Submit(Action<Int32>, Int64)
Suspend() Suspend()

Suspends the execution of the queue.


Equality(DispatchQueue, DispatchQueue) Equality(DispatchQueue, DispatchQueue)
Inequality(DispatchQueue, DispatchQueue) Inequality(DispatchQueue, DispatchQueue)

Applies to

See also