Asp.net scheduled task execution (timer improvement)

Source: Internet
Author: User

Source code: Click to download the source code

Run the code in application_start of Global. asax.

A problem occurs here, that is, you cannot use httpcontext. Current. server. mappath ("~ /Xxx.txt "); an error is returned: NULL reference!

Then google found the solution: system. Web. Hosting. hostingenvironment. mappath ("~ /Xxx.txt "); replace!

 

The original code was found online (the link cannot be found ......), It can only be written to one class. The modified class can be executed after being set by default. aspx.

At first, I used a model layer to store the set time. Later I found that it was not working because the program first loaded global. the code in asax (if you set a breakpoint, you can see it). At this time, the interface has not been loaded, so the data in the model is empty, and it is useless even if you have finished setting, because Global has been executed.

There is no way to think of a stupid method later, that is, to write the set to a TXT file through the default. aspx page, and read it from it when the program is running. That's all.

Source code: Click to download the source code

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.