Through the Global.asax Application_Start method in the website
Add Timer timed Call WebService
The webservice is responsible for a method in the background
To add data to a table in a database
Steps:
1. Create a new Web site by vs
2. Join Global.asax
3. Join WebService Edit and add references
4. Edit the Global.asax
5. Save Run Site View effect
=============================
1. Create a new Web site by vs
2. Join Global.asax
-----------------
The default content is as follows:
<%@ application Language= "C #"%>
<script runat= "Server" >
void Application_Start (object sender, EventArgs e)
{
Code that runs when the application starts
}
void Application_End (object sender, EventArgs e)
{
Code that runs when the application shuts down
}
void Application_Error (object sender, EventArgs e)
{
Code that runs when an unhandled error occurs
}
void Session_Start (object sender, EventArgs e)
{
Code that runs when a new session starts
}
void Session_End (object sender, EventArgs e)
{
Code that runs at the end of the session.
Note: Only the sessionstate mode in the Web.config file is set to
The Session_End event is raised when InProc. If the session mode is set to StateServer
or SQL Server, the event is not raised.
}
</script >
3. Join WebService Edit and add references
4. The following edits are made to Global.asax:
----------------------------
System.Timers.Timer MyTimer = new System.Timers.Timer (3000);
void Application_Start (object sender, EventArgs e)
{
Code that runs when the application starts
mytimer.elapsed + = new System.Timers.ElapsedEventHandler (ontimedevent);
Mytimer.interval = 3000;
Mytimer.enabled = true;
}
private static void Ontimedevent (object source, System.Timers.ElapsedEventArgs e)
{
localhost. Service1 a = new localhost. Service1 ();
string s = A.helloworld ();
}
void Application_End (object sender, EventArgs e)
{
Mytimer.dispose ()//code that runs when the application shuts down
}
5. Save Run Site View effect
From: http://blog.163.com/cristianojzhou@126/blog/static/166335404201082903327241/