Asp.net scheduled execution Program

Source: Internet
Author: User

To implement the above functions in a project, add a global. aspx file to the project.

Public class Global: system. Web. httpapplication
{

Protected void application_start (Object sender, eventargs
E)
{
// Define the timer
System. Timers. Timer
Mytimer = new system. Timers. Timers (5000 );
Mytimer. elapsed + = new
Elapsedeventhandler (mytimer_elapsed );
Mytimer. Enabled =
True;
Mytimer. autoreset = true;
}

Void mytimer_elapsed (Object source, elapsedeventargs E)

{
Try
{

Log. savenote (datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS") + ": autotask is
Working! ");
Yourtask ();
}
Catch
(Exception ee)
{

Log. saveexception (EE );
}
}

Void yourtask ()
{

// Write the task you want to execute here
Log. savenote (datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS ") +": Start of collection! ");
}

Protected void application_end (Object sender, eventargs
E)
{
Log. savenote (datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS ") +": Application end! ");

// The Code below is the key, this solution solves the issue of automatic collection of IIS application Programs pools
thread. sleep (1000);
// set your web address here to point to any of your Aspx pages or even non-existent pages, the purpose is to activate application_start.

String url = "http: // localhost: 8031/default. aspx ";

Httpwebrequest myhttpwebrequest =
(Httpwebrequest) webrequest. Create (URL );
Httpwebresponse
Myhttpwebresponse =
(Httpwebresponse) myhttpwebrequest. getresponse ();
Stream
Receivestream = myhttpwebresponse. getresponsestream (); // get the write-back byte stream

}
}

Original article:

Http://www.cnblogs.com/yangxiaohu1/archive/2010/02/06/net-autotask.html

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.