Edit

Share via


DispatchQueue Class

Definition

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

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

Remarks

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.

Constructors

DispatchQueue(IntPtr)

Surfaces an unmanaged DispatchQueue as a managed object.

DispatchQueue(String, Boolean)

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

DispatchQueue(String, DispatchQueue+Attributes, DispatchQueue)
DispatchQueue(String)

Creates a named dispatch queue that serializes all submitted blocks.

Properties

Context

User defined context information attachech to a DispatchQueue.

CurrentQueue

Developers should not use this deprecated property.

CurrentQueueLabel

Label for the current queue.

DefaultGlobalQueue

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

Handle (Inherited from DispatchObject)
Label

Returns the label for this DispatchQueue.

MainQueue

Returns the main global queue.

QualityOfService

Methods

Activate() (Inherited from DispatchObject)
Check()
Obsolete.
(Inherited from DispatchObject)
DispatchAfter(DispatchTime, Action)

Executes this time on or after the specified time.

DispatchAfter(DispatchTime, DispatchBlock)
DispatchAsync(Action)
DispatchAsync(DispatchBlock)
DispatchBarrierAsync(Action)

Submits a barrier block for asynchronous execution on a dispatch queue

DispatchBarrierAsync(DispatchBlock)
DispatchBarrierSync(Action)
DispatchBarrierSync(DispatchBlock)
DispatchSync(Action)
DispatchSync(DispatchBlock)
Dispose() (Inherited from DispatchObject)
Dispose(Boolean) (Inherited from DispatchObject)
Equals(Object)
GetGlobalQueue(DispatchQueuePriority)

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

GetHashCode()
GetQualityOfService(Int32)
GetSpecific(IntPtr)
InitializeHandle(IntPtr) (Inherited from NativeObject)
MainIteration()
Release() (Inherited from DispatchObject)
Resume()

Resumes execution of the queue.

Retain() (Inherited from DispatchObject)
SetSpecific(IntPtr, Object)
SetTargetQueue(DispatchQueue) (Inherited from DispatchObject)
Submit(Action<Int32>, Int64)
Suspend()

Suspends the execution of the queue.

Operators

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

Applies to

See also