Home>

In the asp.net program, you can implement the timer function through the time component.But it is not the same as the task plan in the database,It must be based on the program being run for it to take effect.The database task plan does not need to run tasks based on asp.net program running.

Here is a practical case:

There is a need for a project,It is necessary to regularly call the webservice of a web system of another company and import the data in their system into our system.Since the web interface is called, this cannot be achieved using the task plan in the database.Later I thought of using the time component and using the application in global.

using system;
using system.collections;
using system.configuration;
using system.data;
using system.linq;
using system.web;
using system.web.security;
using system.web.sessionstate;
using system.xml.linq;
namespace mynet
{
 public class global:system.web.httpapplication
 {
  protected void application_start (object sender, eventargs e)
  {
   system.timers.timer timer1=new system.timers.timer ();
   timer1.interval=30000;//30000 milliseconds=30 seconds
   timer1.elapsed +=new system.timers.elapsedeventhandler (time1_elapsed);
   timer1.autoreset=true;
   timer1.enabled=true;
   timer1.start ();
  }
  protected void session_start (object sender, eventargs e)
  {
  }
  protected void application_beginrequest (object sender, eventargs e)
  {
  }
  protected void application_authenticaterequest (object sender, eventargs e)
  {
  }
  protected void application_error (object sender, eventargs e)
  {
  }
  protected void session_end (object sender, eventargs e)
  {
  }
  protected void application_end (object sender, eventargs e)
  {
  }
  void time1_elapsed (object source, system.timers.elapsedeventargs e)
  {
   localhost.mywebservice ws=new localhost.mywebservice ();
   ws.insertmywebservice ();
  }
 }
}

Note:It will not be affected by the use of the system by multiple users.But at least one user must be using the system,Otherwise, the timer program will not be executed.

  • Previous The most complete and practical regular expressions
  • Next JS implements black style web page TAB tab effect code