Using timer to solve the problem is very simple, first set the Timer class interval attribute (in milliseconds), that is, the time interval, and then in the timer elapsed event to write the execution code, every time a set of interval interval, The events in the elapsed will be executed (this is basically the same as the timer control in the VB program).
That knows what class to use, where is this code written? Write the code in the Global.asax, right-click on the item on VS, click Add--New item, select Global Application class, there will be Global.asax files in the project.
To express clearly the code directly (first introduce the system.timers named control in the Global.asax file header):
<span style= "FONT-SIZE:18PX;" > Public class Global:System.Web.HttpApplication
{
//This code starts protected void at the same time as the site is running
application_ Start (object sender, EventArgs e)
{
System.Timers.Timer objtimer = new System.Timers.Timer ();
Objtimer.interval = 60*1000; This time unit: milliseconds
objtimer.enabled = true; Sets the availability of the Timer class
//Binds the timer's Elapsed event to the newly created timer object
objtimer.elapsed + = new Elapsedeventhandler (objtimer_ Elapsed);
} </span>
The following is the code in the timer's elapsed event
<span style= "FONT-SIZE:18PX;" >void objtimer_elapsed (object sender, Elapsedeventargs e)
{
string time = DateTime.Now.ToShortTimeString () //Get current time
//time to get current setting from configuration file.
string ordertime = configurationmanager.appsettings["Orderfoodtime"];
/* Test Data */If
(Time.equals (ordertime))
{
//If the time is equal, perform the action you want to perform, here you can call the methods of the other classes in your program
}
}</span >
This will achieve the purpose of the scheduled execution of the program.
This is used in my project on a regular basis, in the forum asked about the timing of the implementation of the program, but also said that the use of Windows services more secure