windows service
来源:互联网 发布:洛奇英雄传优化补丁 编辑:程序博客网 时间:2024/06/02 14:33
一、新建工程
二、添加Timer类
Service1.Designer.cs文件中
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "Service1";
_timer = new Timer();
// 每隔5分钟执行
this._timer.Interval = 5000;// 5 * 60 * 1000;
// 设置timer可以激发Elapsed事件
this._timer.Enabled = true;
// 开始
this._timer.Start();
this._timer.Elapsed += new System.Timers.ElapsedEventHandler(this._timer_Elapsed);
}
#endregion
#region Timer
public Timer _timer;
public bool _Scan(bool _judge)
{
//TODO
string[] strFile = System.IO.Directory.GetFiles("E:/TestBase/");
if (strFile != null && strFile.Length > 0)
return true;
else
return false;
}
public void _DO_Something()
{
//TODO
string[] strFile = System.IO.Directory.GetFiles("E:/TestBase/");
foreach (string name in strFile)
{
string[] tmp = name.Split('/');
string aimName = "E:/TestAim/" + tmp[2];
if (!System.IO.File.Exists(aimName))
{
System.IO.File.Copy(name, aimName);
System.IO.File.Delete(name);
}
}
}
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
_timer.Interval = 1000;
_timer.Enabled = false;
//if (_Scan(true) == true)
//{
_DO_Something();
//}
_timer.Enabled = true;
}
#endregion
三、添加安装类ProjectInstaller
四、属性设置
Service1属性
将vs2005切换到属性浏览页面,Service1.cs会有以下属性:
Autolog 是否自动写入系统的日志文件
CanHandlePowerEvent 服务时候接受电源事件
CanPauseAndContinue 服务是否接受暂停或继续运行的请求
CanShutdown 服务是否在运行它的计算机关闭时收到通知,以便能够调用 OnShutDown 过程
CanStop 服务是否接受停止运行的请求
ServiceName 服务名
ProjectInstaller属性
ServiceName:安装后Service的名字
StartType:服务启动类型
五、安装、卸载
- Windows service
- windows service
- windows service
- Windows Service
- Windows Service
- Windows Service
- Windows Service
- windows service
- windows service
- Windows API 之 Windows Service
- 创建windows 服务 (windows service)
- Windows 安装 windows Service 步骤
- windows service详解
- Windows service HOW-TO
- 创建Windows Service
- Simple Windows Service Sample
- windows service 程序
- Windows Excel Service
- iptables+squid透明代理+防火墙终极配置
- Solaris Core Analysis, Part 1: mdb
- 编辑词条POSIX
- Solaris Core Analysis, Part 2: Solaris CAT
- 验证查询条件 - 起始时间和终止日期
- windows service
- 删除表内重复的数据
- 计算机中的二进制
- DNS的资源记录总结
- 波士顿大学告诉我们什么才叫做「光世代」
- 如何从国有到民有?
- 关于提高自己Java水平十大技术
- U盘mp3移动硬盘“文件或目录损坏且无法读取”错误的修复
- 在COBOL中调用REXX脚本[转载]