一切福田,不離方寸,從心而覓,感無不通。

.net windows服务程序编写总结

1、在.net中,windows服务的实现类必需继承于System.ServiceProcess.ServiceBase public partial class myService : ServiceBase {   } 2、在windows服务的实现类的构造函数中进行必要的初始化工作,如设置系统标识服务的简短名称等。 public partial class myService : ServiceBase { public SqlBackupService() { ServiceName = "Myservice"; AutoLog = false; CanStop = true; } } 3、重写OnStar和OnStop函数,在OnStar里实现具体功能,OnStop中释放OnStat中创建的资源。 public partial class myService : ServiceBase { private int tickcount = 0; private System.Timers.Timer t = null;   public SqlBackupService() { ServiceName = "Myservice"; AutoLog = false; CanStop = true; }   protected override void OnStart(string[] args) { Console.WriteLine("Myservice start …"); //建立定时器 t = new System.Timers.Timer(10000); t.AutoReset = true; //每隔10000毫秒触发一次 t.Elapsed += new System.Timers.ElapsedEventHandler(myWork); t.Start(); […]

龙生   13 May 2012
View Details