FluentScheduler定时任务
Global Application_Start()调用
{
CarriedOut carreiedout=new CarriedOut();
carreiedout.Start();
}
protected void Application_End(object sender, EventArgs e)
{
try
{
string strUrl = "http://www.baidu.com";// System.Configuration.ConfigurationManager.AppSettings["FS_SelfAddress"];//本程序部署地址
System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl);
System.Net.HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
System.IO.Stream stream = httpWebResponse.GetResponseStream();//得到回写的字节流
httpWebResponse.Close();
}
catch (Exception ex)
{
}
}
//自定义类
public class CarriedOut: IJob, IRegisteredObject
{
private readonly object _lock = new object();
private bool _shuttingDown;
public Registry Start()
{
HostingEnvironment.RegisterObject(this);
Registry registry = new Registry();
registry.Schedule(() => Execute()).ToRunEvery(1).Days().At(1,30);//每天几点执行一次代码
//registry.Schedule(() => Execute()).ToRunEvery(1).Seconds();//每小时执行一次
return registry;
}
public void Execute()
{
lock (_lock)
{
if (_shuttingDown)
{
return;
}
else
{
//执行方法
}
}
}
public void Stop(bool immediate)
{
lock (_lock)
{
_shuttingDown = true;
}
HostingEnvironment.UnregisterObject(this);
}
}