服务器定时任务添加

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_31338557/article/details/82048078

1登录Xshell
2输入命令crontab -e enter
3输入i(或者insert),进入可编辑状态
4找到需要修改的路径,修改时间
5输入Esc,退出可编辑状态
6输入Shift+:+wq enter 保存刚才修改内容
7输入crontab -l查看目录是否修改正确

展开阅读全文

委托 C# 添加定时任务

08-17

session 运行时 从数据库拿出数据 判断时间为今天的 就给他新建一个Timer控件 现在的问题是 绑定委托的时候还没到时间就直接运行了 方法 求改动方案rn代码如下rnrnrnusing System;rnusing System.Collections.Generic;rnusing System.Linq;rnusing System.Web;rnusing DCModel;rnrnpublic class Global : System.Web.HttpApplicationrnrn public Global()rn rn rn public static List ss()rn rnrn DataClassesDataContext dc = new DataClassesDataContext();rn var resurt = (from p in dc.Task_Contentrn where p.ReleaseState == 1rn select p).ToList();rn return resurt;rn rnrn void Application_Start(object sender, EventArgs e)rn rnrn rn rnrn public void time(string sj, int id, string take)rn rn System.Timers.Timer myTimer = new System.Timers.Timer(); rn DateTime dt = DateTime.Now;rn DateTime strTime;rn strTime = Convert.ToDateTime(sj);rn string dtAfter= strTime.ToString();rn DateTime dtTime = Convert.ToDateTime(dtAfter);rn TimeSpan ts1 = new TimeSpan(dt.Ticks);rn TimeSpan ts2 = new TimeSpan(dtTime.Ticks);rn TimeSpan ts = ts1.Subtract(ts2).Duration();rn string dateDi = ts.TotalSeconds.ToString();rn string strDatedi = dateDi.Substring(0, dateDi.IndexOf('.'));rn int dateDiff = Convert.ToInt32(strDatedi);rn myTimer.Interval = dateDiff * 1000;rn myTimer.Enabled = true;rn myTimer.Elapsed += OnTimedEvent(id, take);rn GC.KeepAlive(myTimer);rn rnrn void Application_End(object sender, EventArgs e)rn rnrn rnrn void Application_Error(object sender, EventArgs e)rn rnrn rn void Session_Start(object sender, EventArgs e)rn rn tryrn rn List resurt = ss();rnrn foreach (var a in resurt)rn rn DateTime aa = (DateTime)a.ReleaseStartTime;rnrn if (aa.Subtract(DateTime.Now).Days == 0)rn rnrnrn time("" + aa.ToString("hh:mm"), a.ID, a.TaskID);rnrnrn rnrn rn rn catch (Exception ex)rn rn throw ex;rn rn rnrn void Session_End(object sender, EventArgs e)rn rnrnrnrn rn private static System.Timers.ElapsedEventHandler OnTimedEvent(int id, string take)rn rn DataClassesDataContext dc = new DataClassesDataContext();rn var user = dc.Task_Content.Single(u => u.ID == id);rn user.ReleaseState = 0;rn dc.SubmitChanges();rnrn var users = dc.Task.Single(u => u.TaskID == take);rn users.ReleaseState = 0;rn dc.SubmitChanges();rnrn return null;rn rn 论坛

没有更多推荐了,返回首页