Effect: By adding a timer to the Global.asax Application_Start method of the site WebService the WebService method is responsible for adding data to a table in the background step: 1. Create a new site with VS 2. Join Global.asax 3. Add WebService Edit and Add Reference 4. To global.as
Effect:
Through the Application_Start method in the Global.asax of the website
Join Timer Call WebService
The webservice is responsible for a method in the background
Adding data to a table in a database
Steps:
1. Create a new website with VS
2. Join Global.asax
3. Add WebService Edit and Add Reference
4. Edit the Global.asax
5. Save run web site viewing effect
=============================
1. Create a new website with 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 to run when the application starts
}
void Application_End (object sender, EventArgs e)
{
Code to run when the application shuts down
}
void Application_Error (object sender, EventArgs e)
{
Code to run when an unhandled error occurs
}
void Session_Start (object sender, EventArgs e)
{
Code to run when a new session is started
}
void Session_End (object sender, EventArgs e)
{
//code to run at the end of the session.
//Note: Only the sessionstate mode in the Web. config file is set to
The Session_End event is only raised when //InProc. If the session mode is set to stateserver
//or SQL Server, the event is not raised.
}
</script>
3. Add WebService Edit and add references
4. Make the following edits to Global.asax:
----------------------------
void Application_Start (object sender, EventArgs e)
{
Code to run when the application starts
System.Timers.Timer MyTimer = new System.Timers.Timer (60000);
mytimer.elapsed + = new System.Timers.ElapsedEventHandler (ontimedevent);
Mytimer.interval = 60000;
Mytimer.enabled = true;
}
private static void Ontimedevent (object source, System.Timers.ElapsedEventArgs e)
{
localhost. WebService a = new localhost. WebService ();
string s = A.helloworld ();
}
5. Save run web site viewing effect
Asp. NET timed call WebService running background code