asp.net Global计划任务
2010-01-11 10:51
197 查看
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 qumiao.com
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
//定义定时器
System.Timers.Timer myTimer = new System.Timers.Timer(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()
{
//在这里写你需要执行的任务
}
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页面甚至不存在的页面,目的是要激发Application_Start
//string url = "http://www.qumiao.com";手机主题
string url = "http://localhost:82/111.aspx";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流
}
}
}
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 qumiao.com
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
//定义定时器
System.Timers.Timer myTimer = new System.Timers.Timer(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()
{
//在这里写你需要执行的任务
}
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页面甚至不存在的页面,目的是要激发Application_Start
//string url = "http://www.qumiao.com";手机主题
string url = "http://localhost:82/111.aspx";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流
}
}
}
相关文章推荐
- asp.net 实现所谓的计划任务(举例)
- asp.net 线程控制计划任务
- 利用Timer在ASP.NET中实现计划任务
- [转载]asp.net计划任务-解决应用池回收问题
- Asp.net(C#) windows 服务{用于实现计划任务,事件监控等}
- asp.net web 定时执行任务 定时器 Global.asax
- ASP.NET 定时执行任务 global.asax
- ASP.NET MVC 计划任务(不使用外接程序,.net内部机制实现)
- Asp.net(C#) windows 服务{用于实现计划任务,事件监控等}
- Asp.Net(C#)自动执行计划任务的程序实例分析
- asp.net定时实现计划任务
- Asp.Net(C#)自动执行计划任务的程序实例分析分享
- asp.net实现计划任务
- asp.net 中止Global.asax Application_End事件 避免应用程序池回收 定时任务
- asp.net计划任务-解决应用池回收问题
- asp.net 计划任务管理程序实现,多线程任务加载
- 利用Timer在ASP.NET中实现计划任务的方法(转)
- ASP.NET MVC 使用 FluentScheduler 定时器计划任务
- ASP.NET 计划任务,使用.net内部机制,解决应用池回收问题