Skip to Content
.NET Common Language Runtime Unleashed
book

.NET Common Language Runtime Unleashed

by Kevin Burton
April 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
23h 26m
English
Sams
Content preview from .NET Common Language Runtime Unleashed

System.Timers

Timers are a great addition to the library. Using Events, you can add a timer to a Console application. Listing B.63 shows how to implement a timer (timer.cs).

Listing B.63. Timers Example
 public class TimerMain { private static long lastTickCount = 0; public static void OnElapsedEvent(object source, ElapsedEventArgs e) { if(lastTickCount == 0) { lastTickCount = Environment.TickCount; Console.WriteLine("Hello!!"); } else { long currentTickCount = Environment.TickCount; Console.WriteLine("Hello!! {0} ", currentTickCount - lastTickCount); lastTickCount = currentTickCount; } } static void Main(string [] args) { Timer timer = new Timer(); timer.Elapsed+=new ElapsedEventHandler(OnElapsedEvent); // Set the Interval to 1 second. timer.Interval ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Customizing the Microsoft® .NET Framework Common Language Runtime

Customizing the Microsoft® .NET Framework Common Language Runtime

Steven Pratschner

Publisher Resources

ISBN: 0672321246Purchase book