用Visual C#创建Windows服务程序
时间:2010-09-07 来源:jdmei520
用Visual C#创建Windows服务程序
protected override void OnStart(string[] args)
private void OnFileChanged(Object source, FileSystemEventArgs e)
OnStop()函数即是停止Windows服务的,在该Windows服务中,服务一旦停止,所有的计数器的值都应归零,但是计数器并不提供一个Reset()方法,所以我们只好将计数器中的值减去当前值来达到这个目的。
protected override void OnStop()
|
同时,因为我们的Windows服务是允许暂停并恢复的,所以我们还得重载OnPause()函数和OnContinue()函数,方法很简单,只要设定前面定义的布尔值servicePaused即可。
protected override void OnPause()
|
这样,该Windows服务的主体部分已经完成了,不过它并不有用,我们还必须为其添加安装文件。安装文件为Windows服务的正确安装做好了工作,它包括了一个Windows服务的安装类,该类是重System.Configuration.Install.Installer继承过来的。安装类中包括了Windows服务运行所需的帐号信息,用户名、密码信息以及Windows服务的名称,启动方式等信息。
[RunInstaller(true)]
new System.ServiceProcess.ServiceProcessInstaller();
System.ServiceProcess.ServiceAccount.LocalSystem;
System.ServiceProcess.ServiceStartMode.Automatic;
new System.Configuration.Install.Installer[] {this.spInstaller, this.sInstaller });
(注:源代码文件为Source.rar ) http://www.vchome.net/dotnet/dotnetdocs/dotnet38.htm 相关阅读 更多 +
排行榜 更多 +
|