Timer Class
The Timer will generate an event after a set interval. There is an option to generate a sequence of events instead of just one.
This is in the System.Timers namespace.
Constructors
This creates a new Timer with all properties = default values.
This creates a new Timer with Interval = Amount.
Properties (some of them)
This is boolean and indicates whether the Timer should be raised only one event (false) or a sequence of them (true). Default = true.
This is boolean and indicates whether the Timer should raise events (true) or not (false). Default = false.
This is a double = number of milliseconds between events. Default = 100.
Methods (some of them)
Release the resources used by the Timer.
Set Enabled = true.
Set Enabled = false.
Events (one of them)
The Elapsed event occurs when the appropriate number of milliseconds has passed.
public event ElapsedEventHandler Elapsed
The second argument for the event handler will be of type ElapsedEventArgs, which has one property (get only):
public DateTime SignalTime
giving us the date and time of the event.
Here ElapsedEventHandler is:
public delegate void ElapsedEventHandler(object sender, ElapsedEventArgs e)
Stopwatch Class
The StopWatch class is intended to allow us to measure elapsed time accurately.
It is in the System.Diagnostics namespace.
In a typical Stopwatch scenario, we call the Start method, do something, call the Stop method, and then check elapsed time using the Elapsed property.
Constructor
public StopWatch()
This creates a Stopwatch object. Initially it is stopped, and the elapsed time property is 0.
Properties (some of them)
This will get the total elapsed time as an instance of the TimeSpan struct, which has properties (Days, Hours, Minutes, Seconds, etc,).
This will get the the total elapsed time as a number of milliseconds.
This returns true if the Stopwatch instance is currently running and false otherwise.
Methods (some of them)
Start or resume measuring elapsed time.
Stop measuring elapsed time.
Stop, reset elapsed time to 0 and start again.