基本信息
源码名称:系统定时重启
源码大小:0.05M
文件格式:.rar
开发语言:C#
更新时间:2019-10-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
CS程序有时候存在一些问题,解决很棘手,可能需要让它在某个时间点定时重启一次。可以参考这个案例。
CS程序有时候存在一些问题,解决很棘手,可能需要让它在某个时间点定时重启一次。可以参考这个案例。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
namespace 定时重启
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer1.Enabled = true;
// 定时重启
int intClear = 30 * 1000;
System.Timers.Timer timeClear = new System.Timers.Timer();
timeClear.Elapsed = new ElapsedEventHandler(ReStartApplication);
timeClear.Interval = intClear;
timeClear.Enabled = true;
}
#region 退出系统,并再启动
/// <summary>
/// 退出系统,并再启动
/// </summary>
private void ReStartApplication(object sender, ElapsedEventArgs e)
{
int intClear = 3;
DateTime fromTime = DateTime.Now.AddMinutes(-intClear);
DateTime toTime = DateTime.Now.AddMinutes(intClear);
DateTime time = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") " 00:00:00");
// 凌晨自动重启
//if (DateTime.Compare(fromTime, time) < 0 && DateTime.Compare(toTime, time) > 0)
//{
Stopwatch stw = new Stopwatch();
Application.Restart();
//Application.ExitThread();
//Thread thtmp = new Thread(new ParameterizedThreadStart(run));
//object appName = Application.ExecutablePath;
//Thread.Sleep(1);
//thtmp.Start(appName);
//}
}
private void run(Object obj)
{
Process ps = new Process();
ps.StartInfo.FileName = obj.ToString();
ps.Start();
}
#endregion
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
}
}
}