C# Timer AutoReset

Description

Timer AutoReset Gets or sets a value indicating whether the Timer should raise the Elapsed event each time the specified interval elapses or only after the first time it elapses.

Syntax

Timer.AutoReset has the following syntax.


[TimersDescriptionAttribute("TimerAutoReset")]
public bool AutoReset { get; set; }

Example


/*w  w w . j av  a2  s  .  c  o  m*/
using System;
using System.Timers;

public class Timer2
{
    private static System.Timers.Timer aTimer;

    public static void Main()
    {
        aTimer = new System.Timers.Timer(10000);
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        aTimer.AutoReset = false;
        aTimer.Enabled = true;

        Console.WriteLine("Press the Enter key to exit the program.");
        Console.ReadLine();

        //GC.KeepAlive(aTimer);
    }
    private static void OnTimedEvent(object source, ElapsedEventArgs e) 
    {
        Console.WriteLine("Hello World!");
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Timers »




Timer