For example, send a report by email at seven o'clock in the morning every day.
The first idea here is to use the Global.asax file to implement the contents of the following Global file.
Copy Code code as follows:
<%@ application Language= "C #"%>
<%@ Import namespace= "System.Threading"%>
<script runat= "Server" >
This is used to keep a reference to this timer instance statically, lest the GC
private static System.Threading.Timer Timer = null;
protected void Application_Start (object sender, EventArgs e) {
Calculates the time period that is now to the target time.
DateTime lucktime = DateTime.Now.Date.Add (New TimeSpan (7, 0, 0));
TimeSpan span = Lucktime-datetime.now;
if (span < TimeSpan.Zero) {
span = lucktime.adddays (1d)-DateTime.Now;
}
The status or object to be passed on demand.
Object state = new Object ();
Defining timers
Timer = new System.Threading.Timer (
New TimerCallback (Certaintask), state,
span, Timespan.fromticks (timespan.ticksperday));
}
protected void Application_End (object sender, EventArgs e) {
At the end remember to release
if (timer!= null) {timer. Dispose (); }
}
This is the code that specifies the time to execute, and must be static.
private static void Certaintask (object state) {
Here, write your mission logic.
}
</script>