Tag Archives: timer

Use System.Threading.Timer to make a countdown timer in C#

The post Make a countdown timer in C# uses a Timer control to count down the time until some deadline. This example does something similar but it uses a Timer object from the System.Threading namespace. The basic idea is similar: … Continue reading

Posted in miscellany, system | Tagged , , , , , , , , , , , , | Leave a comment

Make a stopwatch in C#

This program is a simple stopwatch. When you click the Start button, the program changes the button’s caption to Stop and starts a Timer. As the stopwatch Timer runs, the program displays the elapsed time. Click the Stop button to … Continue reading

Posted in internationalization, miscellany, strings | Tagged , , , , , , , , , , , , , | Leave a comment

Draw an analog clock in C#

This example demonstrates several useful techniques including: Context menus Restricting a form to a region to give it a shape. Moving a form with no title bar Double buffering Drawing with transformations Drawing an analog clock When you right-click the … Continue reading

Posted in animation, drawing, forms, graphics | Tagged , , , , , , , , , , , , , , , , , | 2 Comments

Make a countdown timer in C#

When the program starts, it sets the event name and time. It then enables the Timer control. // Initialize information about the event. private const string EventName = “End of the World”; private DateTime EventDate = DateTime.Now + new TimeSpan(1, … Continue reading

Posted in miscellany | Tagged , , , , , , , , | 6 Comments

Measure elapsed time in C#

For most tasks, you can measure elapsed time with the Stopwatch or DateTime classes. To use the Stopwatch class, create a Stopwatch object. Use its Start and Stop methods to start and stop it. If you use Start after stopping … Continue reading

Posted in performance, system | Tagged , , , , , , , , , , , | Leave a comment