InstallUtil.exe
这个文件的位置因人而异,全文搜索一下就行
安装:C:\WINDOWS\Microsoft.NET\Framework64\v4.。。\InstallUtil C:\Progra~1\HoteamSoft\InforCenterServer\InforCenterWindowsService\InforCenterService.exe
卸载: C:\WINDOWS\Microsoft.NET\Framework64\v4.。。\InstallUtil.exe C:\Progra~1\HoteamSoft\InforCenterServer\InforCenterWindowsService\InforCenterService.exe /u
调试
1 附加到进程进行调试
2 直接运行程序调试
修改programe类
2 修改onstart方法
定时任务
public partial class Service1 : ServiceBase
{
System.Timers.Timer timer1; //计时器
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
//服务开启执行代码
//定时调用接口
timer1 = new System.Timers.Timer();
timer1.Interval = 3000; //设置计时器事件间隔执行时间
timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);
timer1.Enabled = true;
timer.AutoReset=true;
}
/// <summary>
/// 定时器 调用的方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://192.168.10.239:9000/");//接口url
string data = client.GetStringAsync("ZyTest").Result;//接口action
}
protected override void OnStop()
{
//服务结束执行代码
this.timer1.Enabled = false;
}
protected override void OnPause()
{
//服务暂停执行代码
base.OnPause();
}
protected override void OnContinue()
{
//服务恢复执行代码
base.OnContinue();
}
protected override void OnShutdown()
{
//系统即将关闭执行代码
base.OnShutdown();
}
}