. Net performs some operations on a regular basis globally in Global. asax.

Source: Internet
Author: User

Copy codeThe Code is as follows:
<% @ Application Language = "C #" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. SqlClient" %>
<% @ Import Namespace = "System. Collections" %>
<% @ Import Namespace = "System. IO" %>
// Introduce the class library
<Script runat = "server">
// Add by chairuirui 2013-3-26
Void Application_Start (object sender, EventArgs e)
{
// Code that runs when the application starts
System. Timers. Timer myTimer = new System. Timers. Timer (60000); // judge every minute
MyTimer. Elapsed + = new System. Timers. ElapsedEventHandler (OnTimedEvent); // code for executing the operation. OnTimedEvent is the name of the method to be executed.
MyTimer. Interval = 60000;
MyTimer. Enabled = true;
}
Void Application_End (object sender, EventArgs e)
{
// Code that runs when the application is closed
}
Void Application_Error (object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
Void Session_Start (object sender, EventArgs e)
{
// The code that runs when the new session starts
}
Void Session_End (object sender, EventArgs e)
{
// The code that runs when the session ends.
// Note: Only the sessionstate mode in the Web. config file is set
// The Session_End event is triggered only when InProc is used. If the session Mode
// If it is set to StateServer or SQLServer, this event is not triggered.
}
Private static void OnTimedEvent (object source, System. Timers. ElapsedEventArgs e)
{
// Write the required operations in this method
}

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.