DispatchSource.Timer Class

Definition

Sources of this type periodically invoke the event handler on the target queue.

public class DispatchSource.Timer : CoreFoundation.DispatchSource
type DispatchSource.Timer = class
    inherit DispatchSource
Inheritance
DispatchSource.Timer
Inheritance

Remarks

The timer parameters are configured with the dispatch_source_set_timer() function. Once this function returns, any pending source data accumulated for the previous timer parameters has been cleared; the next fire of the timer will occur at start, and every interval nanoseconds thereafter until the timer source is canceled.

Any fire of the timer may be delayed by the system in order to improve power consumption and system performance. The upper limit to the allowable delay may be configured with the leeway argument, the lower limit is under the control of the system.

For the initial timer fire at start, the upper limit to the allowable delay is set to leeway nanoseconds. For the subsequent timer fires at start + N * interval, the upper limit is MIN(leeway, interval / 2 ).

The lower limit to the allowable delay may vary with process state such as visibility of application UI. If the specified timer source was created with a the constructor that sets "strict" to true, the system will make a best effort to strictly observe the provided leeway value even if it is smaller than the current lower limit. Note that a minimal amount of delay is to be expected even if this flag is specified.

var dispatchSource = new DispatchSource.Timer (strict: true, queue: DispatchQueue.MainQueue);

long delay = 2000000000;
long leeway = 5000000000;
dispatchSource.SetTimer (DispatchTime.Now, delay, leeway);

dispatchSource.SetRegistrationHandler (() => {
    Console.WriteLine ("Timer registered");
});

dispatchSource.SetEventHandler (() => {
Console.WriteLine ("Timer tick");
});

dispatchSource.SetCancelHandler (() => {
Console.WriteLine ("Timer stopped");
});

dispatchSource.Resume ();

Constructors

DispatchSource.Timer(Boolean, DispatchQueue)
DispatchSource.Timer(DispatchQueue)

Creates a timer dispatch source that will be invoked at periodic intervals.

DispatchSource.Timer(IntPtr, Boolean)
DispatchSource.Timer(IntPtr)

Properties

Handle (Inherited from DispatchObject)
IsCanceled

Determine whether the specified source has been canceled.

(Inherited from DispatchSource)
TimerFiredCount

Number of times the timer has fired since the last invocation of the event handler

Methods

Activate() (Inherited from DispatchObject)
Cancel()

Asynchronously cancels the dispatch source.

(Inherited from DispatchSource)
Check()
Obsolete.
(Inherited from DispatchObject)
Dispose() (Inherited from DispatchObject)
Dispose(Boolean)

Releases the resources used by the DispatchSource object.

(Inherited from DispatchSource)
Equals(Object) (Inherited from DispatchObject)
GetHashCode()

Returns the hashcode for this object

(Inherited from DispatchObject)
InitializeHandle(IntPtr) (Inherited from NativeObject)
Release() (Inherited from DispatchObject)
Resume()

Resumes the dispatch source.

(Inherited from DispatchSource)
Retain() (Inherited from DispatchObject)
SetCancelHandler(Action)

Provides a cancellation handler

(Inherited from DispatchSource)
SetEventHandler(Action)

Specified a handler to execute when events are received on the dispatch source.

(Inherited from DispatchSource)
SetRegistrationHandler(Action)

Provides a registration handler

(Inherited from DispatchSource)
SetTargetQueue(DispatchQueue) (Inherited from DispatchObject)
SetTimer(DispatchTime, Int64, Int64)

Configures the paramters to the timer.

Suspend()

Suspends the dispatch source.

(Inherited from DispatchSource)

Applies to