Working with a Timer in C# Vermont

Implement a simple timer in C#. This excerpt from the upcoming Sams Teach Yourself C# in 21 Days shows you how.

Local Companies

Vermont Computer Support
(802) 524-0203
1 Wiley Pl
Saint Albans, VT
Green Mountain Logic
(802) 223-3729
7 Baldwin St
Montpelier, VT
Microbrightfield Inc
(802) 288-9290
185 Allen Brook Ln
Williston, VT
Custom Software Design
(802) 863-0566
Colchester, VT
Mbf Bioscience
(802) 288-9290
185 Allen Brook Ln
Williston, VT
KGS Software Engineering
(802) 879-7848
Po Box 8286
Essex, VT
Global Works Systems
(802) 846-2550
441 Watertower Cir
Colchester, VT
Results Inc
(802) 288-9997
166 Brigham Hill Rd
Essex Junction, VT
C T G Inc
(802) 860-7172
30 Main St
Burlington, VT
C Y Associates Inc
(802) 434-4994
420 Ridge Dr
Huntington, VT

provided by: 
Originally published at Internet.com


This article is an excerpt from the book Sams Teach Yourself the C# Language in 21 Days.

The following listing presents a neat little program that is not well designed. It is simple, and there is nothing complex presented in it. It simply prints the time to the console. Forever.

Listing 1. timer.cs - Displaying the time. 1: // Timer01.cs - Displaying Date and Time 2: // Not a great way to do the time. 3: // Press Ctrl+C to end program. 4: //--------------------- 5: using System; 6: 7: class myApp 8: { 9: public static void Main() 10: { 11: while (true) 12: { 13: Console.Write("r{0}", DateTime.Now); 14: } 15: } 16: }

5/26/2003 9:34:19 PM

As you can see, this listing was executed at 9:34 on May the 26th. This listing presents a clock on the command line. This clock seems to update the time every second. Actually it us updating much more often than that; however, you only notice the changes every second when the value being displayed actually changes. This program runs until you break out of it using Ctrl+C.

In line 13, a call to DateTime is made. DateTime is a structure that is available from the System namespace within the base class libraries. This structure has a static method called Now that returns the current time. There are a large number of additional data members and methods within the DateTime structure. You can check out the .NET Framework class library documentation for information on these. There are also a few other aritcles here on CodeGuru.com ...

Read article at Internet.com site

Featured Local Company

KGS Software Engineering

8028797848
Po Box 8286
Essex, VT
http://www.kgsse.com


Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML