window服务创建

第一步:创建服务

第二步:在Service1.cs视图中 右键 选择”添加安装程序”

这里要注意几个细节 设置上面的属性 这两个分别有属性,具体网上查使用方式

3 实例代码编写 主要下面几个方法

 protected override void OnStart(string[] args)
        {
           
            timer.Interval = 1000 * 60*24;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Start();
        }
        protected void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            
        }
        protected override void OnStop()
        {
            timer.Stop();
        }

服务写好了后,需要生成

生成成功后,需要打开该项目生成exe的路径

最后一步也就是最重要的一步安装了

打开vs命令提示符,注意要以管理员的身份啊,不然会安装失败。

InstallUtil.exe D:\Documents\Visual_Studio_2010\Projects\WindowsService\ZZ_WindowsService\bin\Debug\ZZ_WindowsService.exe (注意事项:路径不允许有空格,具体路径就是你的window服务生产路径)

卸载 window服务路径

输入 InstallUtil.exe /u 空格  D:\Documents\Visual_Studio_2010\Projects\WindowsService\ZZ_WindowsService\bin\Debug\ZZ_WindowsService.exe

posted @ 2014-07-28 15:48  dzp123456  阅读(606)  评论(0编辑  收藏  举报