Search Results for

    Show / Hide Table of Contents

    Class Timer

    Provides a mechanism for executing a method on a thread pool thread at specified intervals. This class cannot be inherited.

    Inheritance
    object
    MarshalByRefObject
    Timer
    Implements
    IDisposable
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    Namespace: System.Threading
    Assembly: mscorlib.dll
    Syntax
    public sealed class Timer : MarshalByRefObject, IDisposable

    Constructors

    Timer(TimerCallback, object, int, int)

    Initializes a new instance of the Timer class, using a 32-bit signed integer to specify the time interval.

    Declaration
    public Timer(TimerCallback callback, object state, int dueTime, int period)
    Parameters
    Type Name Description
    TimerCallback callback

    A TimerCallback delegate representing a method to be executed.

    object state

    An object containing information to be used by the callback method, or null.

    int dueTime

    The amount of time to delay before callback is invoked, in milliseconds. Specify Timeout.Infinite to prevent the timer from starting. Specify zero (0) to start the timer immediately.

    int period

    The time interval between invocations of callback, in milliseconds. Specify Timeout.Infinite to disable periodic signaling.

    Timer(TimerCallback, object, TimeSpan, TimeSpan)

    Initializes a new instance of the Timer class, using TimeSpan values to measure time intervals.

    Declaration
    public Timer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)
    Parameters
    Type Name Description
    TimerCallback callback

    A delegate representing a method to be executed.

    object state

    An object containing information to be used by the callback method, or null.

    TimeSpan dueTime

    The amount of time to delay before the callback parameter invokes its methods. Specify negative one (-1) milliseconds to prevent the timer from starting. Specify zero (0) to start the timer immediately.

    TimeSpan period

    The time interval between invocations of the methods referenced by callback. Specify negative one (-1) milliseconds to disable periodic signaling.

    Methods

    Change(int, int)

    Changes the start time and the interval between method invocations for a timer, using 32-bit signed integers to measure time intervals.

    Declaration
    public bool Change(int dueTime, int period)
    Parameters
    Type Name Description
    int dueTime

    The amount of time to delay before the invoking the callback method specified when the Timer was constructed, in milliseconds. Specify Timeout.Infinite to prevent the timer from restarting. Specify zero (0) to restart the timer immediately.

    int period

    The time interval between invocations of the callback method specified when the Timer was constructed, in milliseconds. Specify Timeout.Infinite to disable periodic signaling.

    Returns
    Type Description
    bool

    true if the timer was successfully updated; otherwise, false.

    Change(TimeSpan, TimeSpan)

    Changes the start time and the interval between method invocations for a timer, using TimeSpan values to measure time intervals.

    Declaration
    public bool Change(TimeSpan dueTime, TimeSpan period)
    Parameters
    Type Name Description
    TimeSpan dueTime

    A TimeSpan representing the amount of time to delay before invoking the callback method specified when the Timer was constructed. Specify negative one (-1) milliseconds to prevent the timer from restarting. Specify zero (0) to restart the timer immediately.

    TimeSpan period

    The time interval between invocations of the callback method specified when the Timer was constructed. Specify negative one (-1) milliseconds to disable periodic signaling.

    Returns
    Type Description
    bool

    true if the timer was successfully updated; otherwise, false.

    Dispose()

    Releases all resources used by the current instance of Timer.

    Declaration
    public void Dispose()

    Implements

    IDisposable

    Extension Methods

    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    In This Article
    Back to top Copyright © 2023 nanoFramework Contributors
    Generated by DocFX