usingSystem;usingsystem.timers;namespacedaochucore2{classProgram {Static voidMain (string[] args) {System.Timers.Timer Atimer=NewSystem.Timers.Timer (); Atimer.elapsed+=NewElapsedeventhandler (timeevent); //set the time interval to raise the time here to 1 seconds (1000 milliseconds)Atimer.interval = +; Atimer.enabled=true; Console.WriteLine ("press ENTER to end the program"); Console.WriteLine ("waiting for the execution of the program ... "); Console.readkey (); } Private Static voidTimeevent (Objectsource, Elapsedeventargs E) {Console.WriteLine ("Enter the timer monitor program ..."); //get hour minute second start executing a program if it equals a value. DateTime date1 =E.signaltime; intInthour =E.signaltime.hour; intIntminute =E.signaltime.minute; intIntsecond =E.signaltime.second; //Console.WriteLine (Inthour); //Console.WriteLine (Intminute); //Console.WriteLine (Intsecond); //custom time, such as executing a function when 10:30:00 intIhour =Ten; intIminute = -; intIsecond = on; //set how many seconds to start execution if(Intsecond = =Isecond) {Console.WriteLine ("start execution once per second! "); } //set 30 minutes per hour to start execution if(Intminute = = Iminute && Intsecond = =Isecond) {Console.WriteLine ("30 minutes per hour to start the execution! "); } //set the program to start 10:30:00 every day if(Inthour = = Ihour && Intminute = = Iminute && Intsecond = =Isecond) {Console.WriteLine ("start at 10:30 every day! "); } } }}
C # Console Timer program