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);
        }

    }

转载于:https://www.cnblogs.com/hujiangcheng/p/7371652.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值