Browse Source

新增凌晨2点清理本地缓存文件

master
胡超1 1 year ago
parent
commit
175e114a9d
  1. 19
      CPF_Cef/Common/Utils.cs
  2. 39
      CPF_Cef/FrmMain.cs
  3. 1
      CPF_Cef/MainModel.cs

19
CPF_Cef/Common/Utils.cs

@ -34,5 +34,24 @@ namespace AksWebBrowser.Common
fileStream.Close(); fileStream.Close();
} }
} }
//删除目录下文件
public static void DeleteAllFiles(string folderPath)
{
// 确保文件夹路径是完整的,并且文件夹存在
if (!Directory.Exists(folderPath))
{
Log.Error("未找到删除临时目录");
}
// 获取文件夹内所有文件,包括子文件夹内的文件
string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
// 删除所有文件
foreach (string file in files)
{
File.Delete(file);
}
}
} }
} }

39
CPF_Cef/FrmMain.cs

@ -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")

1
CPF_Cef/MainModel.cs

@ -38,6 +38,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
public static Process recordingProcess; public static Process recordingProcess;
public static Process Typrocess; public static Process Typrocess;
private string srpath = string.Empty; private string srpath = string.Empty;
/// <summary> /// <summary>
/// 读取身份证卡号(已国产化) /// 读取身份证卡号(已国产化)
/// </summary> /// </summary>

Loading…
Cancel
Save