|
|
@ -14,6 +14,7 @@ using AKSWebBrowser.Commen; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Reflection.Metadata; |
|
|
|
using System.Reflection.Metadata; |
|
|
|
using AksWebBrowser.Common; |
|
|
|
using AksWebBrowser.Common; |
|
|
|
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
|
|
namespace AKS.EnterpriseLibrary.WebBrowser |
|
|
|
namespace AKS.EnterpriseLibrary.WebBrowser |
|
|
|
{ |
|
|
|
{ |
|
|
@ -102,6 +103,44 @@ namespace AKS.EnterpriseLibrary.WebBrowser |
|
|
|
} |
|
|
|
} |
|
|
|
//获取授权 |
|
|
|
//获取授权 |
|
|
|
GetSQObject(); |
|
|
|
GetSQObject(); |
|
|
|
|
|
|
|
Task.Run(() => { Time(); }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//凌晨2点执行,清理当天缓存文件 |
|
|
|
|
|
|
|
public void Time() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// 获取当前时间 |
|
|
|
|
|
|
|
DateTime now = DateTime.Now; |
|
|
|
|
|
|
|
// 计算明天凌晨的时间// 假设凌晨2点执行 |
|
|
|
|
|
|
|
DateTime tomorrowMorning = new DateTime(now.Year, now.Month, now.Day) + TimeSpan.FromDays(1) + TimeSpan.FromHours(2); |
|
|
|
|
|
|
|
// 计算时间差(明天凌晨时间减去现在时间) |
|
|
|
|
|
|
|
TimeSpan timeToGo = tomorrowMorning - now; |
|
|
|
|
|
|
|
// 设置定时器 |
|
|
|
|
|
|
|
Timer timer = new Timer(ExecuteTask, null, timeToGo, Timeout.InfiniteTimeSpan); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("定时任务开启异常: " + ex.Message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 要执行的任务 |
|
|
|
|
|
|
|
private static void ExecuteTask(object state) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Info("定时任务执行时间: " + DateTime.Now); |
|
|
|
|
|
|
|
string file = System.IO.Directory.GetCurrentDirectory(); |
|
|
|
|
|
|
|
file = file + @"/aks/wwwroot"; |
|
|
|
|
|
|
|
// 这里添加你的任务代码 |
|
|
|
|
|
|
|
Utils.DeleteAllFiles(file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.Error("定时任务执行异常: " + ex.Message); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Writelog(string str, string dirName = @"logs") |
|
|
|
public void Writelog(string str, string dirName = @"logs") |
|
|
|