Utils/TimerUtils.cs
(开头部分) 15KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using AppManager.Config;
using AppManager.Pojo;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppManager.Utils {
internal static class TimerUtils {
// 不能使用窗体中的timer控件,要使用线程timer
private static System.Timers.Timer _gcTimer = new System.Timers.Timer(5 * 60 * 1000);
private static readonly System.Timers.Timer OperateMessageTimer = new System.Timers.Timer(3000);
private static System.Timers.Timer _monitorTimer = new System.Timers.Timer();
private static System.Timers.Timer serverInfoTimer = new System.Timers.Timer();
static TimerUtils() {
OperateMessageTimer.Elapsed += OperateMessageTimer_Tick;
}
/// <summary>
/// 自动GC定时器初始化
/// </summary>
internal static void AutoGc() {
// 每5分钟执行一次GC
_gcTimer.Interval = 5 * 60 * 1000;
_gcTimer.Enabled = true;
// 给时间控件绑定事件
_gcTimer.Elapsed += GCTimer_Tick;
_gcTimer.AutoReset = true;
}
internal static void Monitor() {
_monitorTimer.Interval = Configs.monitorInterval;
_monitorTimer.Enabled = true;
_monitorTimer.Elapsed += MonitorTimer_Tick;
_monitorTimer.AutoReset = true;
}
/// <summary>
/// 定时GC任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void GCTimer_Tick(object sender, EventArgs e) {
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
// 配置工作使用空间
DllUtils.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
后面还有 275 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。