C # Console Timer program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.