代码拉取完成,页面将自动刷新
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace StudentSynchronization.Daemon
{
/// <summary>
/// 周期任务
/// </summary>
public class QuartzWork
{
//0 0/1 * * * ?
public void Start()
{
// 启动后台线程
Thread backgroundThread = new Thread(StartBackgroundThread);
backgroundThread.IsBackground = true; // 设置为后台线程
backgroundThread.Start();
}
public static WinProcess winpro = new WinProcess();
private static void StartBackgroundThread()
{
try
{
// 保持后台线程运行
while (true)
{
ProcessData.processlist.Where(p => p.IsRestart).ToList().ForEach(pro =>
{
Task.Run(() =>
{
try
{
var profullname = pro.Path + Path.DirectorySeparatorChar + pro.Name;
if (File.Exists(profullname))
{
var findpro = Process.GetProcessesByName(pro.Name.Replace(".exe", "")).FirstOrDefault(p => p.MainModule.FileName == pro.Path + Path.DirectorySeparatorChar + pro.Name);
if (findpro == null || findpro.Id == 0)
{
winpro.SetForm(pro.Path + Path.DirectorySeparatorChar + pro.Name, pro.Path, pro.Name);
Thread.Sleep(500);
findpro = Process.GetProcessesByName(pro.Name.Replace(".exe", "")).FirstOrDefault(p => p.MainModule.FileName == pro.Path + Path.DirectorySeparatorChar + pro.Name);
}
if (ProcessData.needwindows == "true")
{
ProLogic.Instance.ReStartPro(pro.IndexNum, findpro.Id, 0);
}
}
else if (pro.Info != "配置错误")
{
pro.Info = "配置错误";
if (ProcessData.needwindows == "true")
{
ProLogic.Instance.UpdatePro(pro.IndexNum);
}
}
}
catch
{
}
});
});
if (float.TryParse(ProcessData.timecron, out float timeout))
Thread.Sleep((int)(timeout * 1000)); // 每秒检查一次
else
Thread.Sleep(5000);
}
}
catch (Exception ex)
{
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。