Skip to content

Page 2: Setting Up The Timer

Colin Kiama edited this page Jan 14, 2018 · 1 revision

How To Create A Timer Object:

Default Timer:

// Creates a new timer. Its default interval is 100 milliseconds
// and its default duration is 30 seconds

Timer myTimer = new Timer();

Timer With Custom Duration:

// Creates a new timer with a duration of 20 minutes. 
// Its default interval is 100 milliseconds.

TimeSpan myDuration = new TimeSpan(0,20,0); 
Timer myTimer = new Timer(myDuration);

Timer With Custom Duration And Custom Timer Tick Interval:

// Creates a new timer with a duration of 20 minutes 
// and a timer tick interval of 100 milliseconds

TimeSpan myDuration = new TimeSpan(0,20,0); 
TimeSpan myInterval = new TimeSpan(0,0,0,0,100); 
Timer myTimer = new Timer(myDuration, myInterval);