using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Timers;
using System.Net;
using System.IO;
using System.Text;
using System.Threading; namespace DTcms.Web
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
//定义定时器
System.Timers.Timer myTimer = new System.Timers.Timer(1000);
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()
{
if (DateTime.Now.ToString("HH:mm") == "15:20")
{
//在这里写你需要执行的任务
DTcms.BLL.article bll = new DTcms.BLL.article();
DTcms.Model.article_news model = new Model.article_news();
model.title = "定时任务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
model.channel_id = 1;
model.category_id = 1;
bll.Add(model);
}
} protected void Application_End(object sender, EventArgs e)
{
// Log.SaveNote(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") ":Application End!"); //下面的代码是关键,可解决IIS应用程序池自动回收的问题
Thread.Sleep(1000);
//这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Ap plication_Start
string url = "http://cpzy.net/e.aspx";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流 }
}
}

最新文章

  1. Oracle 的字符集与乱码
  2. java多线程系类:JUC线程池:01之线程池架构
  3. RabbitMQ安装后不能运行 Error: unable to connect to node nodedown
  4. Qunie问题
  5. ————————————————————————————杭电ACM————————————————X-POWER————————————————————————————————
  6. 典当行以及海尔java小节
  7. decimal to hexadecimal,binary and octonary.
  8. 如何往IE工具条添加按钮(转载)
  9. (Problem 19)Counting Sundays
  10. Struts2--模块包含
  11. Redis讲解以及测试要点
  12. Atom插件下载失败解决办法
  13. 2017.07.09【NOIP提高组】模拟赛B组
  14. [转]Go语言中的make和new
  15. String拼接
  16. T4学习- 2、创建设计时模板
  17. 图片上传前预览、压缩、转blob、转formData等操作
  18. 浏览器缓存机制介绍 + 常用 http 状态码
  19. 异构GoldenGate 12c 双向复制配置
  20. UEFI BIOS和普通BIOS的区别

热门文章

  1. 分享一段ios数据库代码,包括对表的创建、升级、增删查改
  2. WebApp分析建模的工具
  3. 从Oracle迁移到MySQL的各种坑及自救方案
  4. [Web 前端] this作用域问题
  5. Orchard之在前台显式一个属于自己的列表
  6. glyphicons-halflings-regular.woff2:1 Failed to load resource: the server responded with a status of 404 (Not Found)解决Web部署 svg/woff/woff2字体 404错误
  7. 以双斜杠//开头的URL的含义
  8. the network bridge on device vmnet0 is not running解决方法
  9. 读书笔记,《Java 8实战》第五章,使用流
  10. vue-自定义组件传值