Switch to] C # regularly execute a program

Source: Internet
Author: User
Using System;
Using System. Timers;
Namespace Timer leleapplication1
Class Class1
Static   Void Main ( String [] ARGs)
System. Timers. Timer atimer =   New System. Timers. Timer ();
Atimer. elapsed + =   New Elapsedeventhandler (timeevent );
// Set the interval of the triggering time to 1 second (1000 ms)
Atimer. Interval =   1000 ;
Atimer. Enabled =   True ;
Console. writeline ( " Press enter to endProgram " );
Console. writeline ( " Waiting for program execution ...... " );
Console. Readline ();
// Logic processing required when time occurs
// There is only one way to achieve this.
Private   Static   Void Timeevent ( Object Source, elapsedeventargs E)
// If the value of hour minute second is equal to a value, a program is executed.
Int Inthour = E. signaltime. hour;
Int Intminute = E. signaltime. minute;
Int Intsecond = E. signaltime. Second;
// Custom time. For example, a function is executed.
Int Ihour =   10 ;
Int Iminute =   30 ;
Int Isecond =   00 ;
// Set the execution to start once every second.
If (Intsecond = Isecond)
Console. writeline ("The execution starts once every second!");
// Set to start execution 30 minutes per hour
If (Intminute = Iminute && Intsecond = Isecond)
Console. writeline ("Execute once every 30 minutes of the hour!");

// Set the program to start running at 10:30:00 every day
If (Inthour = Ihour && Intminute = Iminute && Intsecond = Isecond)
Console. writeline ("It starts at every day!");
Related Article

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.