1:vs中创建一个 window servece
2.右键 添加安装程序
3.更改属性视图中的Account属性为LocalService(本地服务) 更改ServiceName为你自己的服务名称 StartType默认为手动,可以更改为自动
创建一个定时器
Timer aTimer = new Timer();
aTimer.Interval = 3000 * 1000;
aTimer.Elapsed += new ElapsedEventHandler(TimedEvent);
aTimer.Enabled = true;
/// <summary>
/// 开始周期执行函数 --
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private void TimedEvent(object source, ElapsedEventArgs e)
{
Action();
}
4.添加到服务中: 找到 菜单-》所有程序-》Visual Studio 2013->Visual Studio Tools ->VS2013 开发人员命令提示
进入安装程序的目录,输入:installutil LifePower.exe 就可以安装了。
卸载进入目录:installutil /u LifePower.exe 即卸载
InstallUtil.exe 默认的安装位置是在C:/Windows/Microsoft.NET/Framework/v4.0.30319
sc delete 服务名称 ---卸载服务
matlab 引用库 要放到 c:\windows\system32 目录下面。只放到项目目录下面会 找不到。如果是控制台程序放到运行目录下面 就可以正常运行。window service 运行目录在System32 下面。