没有合适的资源?快使用搜索试试~ 我知道了~
C#创建Windows服务(Windows Services) 实战之系统定时重启服务.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 106 浏览量
2022-07-05
04:02:10
上传
评论
收藏 62KB DOC 举报
温馨提示
试读
5页
C#创建Windows服务(Windows Services) 实战之系统定时重启服务
资源推荐
资源详情
资源评论
//服务器重启服务,作者:柳永法 www.yongfa365.com
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.IO;
using System.Text;
using System.Timers;
namespace CBDCN_reboot
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
double sleeptime = ValidatorDate1(System.DateTime.Now.ToString("yyy-MM-dd HH:mm:ss"),
System.DateTime.Now.ToString("yyy-MM-dd ") + "07:00:00");
if (sleeptime < 0) sleeptime += 24 * 60 * 60 * 1000;
writestr("开始",sleeptime);
System.Timers.Timer t = new System.Timers.Timer(sleeptime);//实例化 Timer 类,设置间隔时间为 10000 毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(rebootsystem);//到达时间的时候执行事件;
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;//是否执行 System.Timers.Timer.Elapsed 事件;
writestr("结束", sleeptime);
}
public void rebootsystem(object source, System.Timers.ElapsedEventArgs e)
{
System.Diagnostics.Process.Start("shutdown", "/r /f /t 0");
}
public static double ValidatorDate1(string strDateA, string strDateB)
{
string strFrom = strDateB;
string strTo = strDateA;
TimeSpan ts = Convert.ToDateTime(strFrom) - Convert.ToDateTime(strTo);
资源评论
老帽爬新坡
- 粉丝: 79
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功