Effect:
In the application_start method of Global. asax of the website
Add a timer to regularly call WebService
A method of this WebService is responsible
Add data to a table in the database
Steps:
1. Create a website through
2. Join global. asax
3. Add WebService edit and reference
4. Edit global. asax
5. Save the running website to view the effect
==================================
1. Create a website through
2. Join global. asax
-----------------
The default content is as follows:
<% @ Application language = "C #" %>
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 is set to StateServer
// Or sqlserver, the event is not triggered.
}
</SCRIPT>
3. Add WebService edit and reference
4. Edit global. asax as follows:
----------------------------
Void application_start (Object sender, eventargs E)
{
// Code that runs 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 the running website to view the effect