c#如何写服务,打包和卸载服务

时间:2014-10-29 12:46:58   收藏:0   阅读:276

Service.cs  每隔一分钟进行一次数据操作

   public Service1()
        {
            InitializeComponent();
            System.Timers.Timer mtimer = new System.Timers.Timer();
            mtimer.Elapsed += new System.Timers.ElapsedEventHandler(mtimer_Elapsed);
            mtimer.Enabled = true;
            mtimer.Interval = 1000*60;
        }

        void mtimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            dolog("抓取数据");
            GetData();//数据操作部分
        }

 

        protected override void OnStart(string[] args)
        {
            dolog("服务运行");//记录日志
        }

        protected override void OnStop()
        {
            dolog("服务停止");//记录日志
        }

 

安装和卸载

1输入cmd命令

2输入InstallUtil.exe 路径//安装

3输入InstallUtil.exe -u 路径//卸载

 

原文:http://www.cnblogs.com/apes-monkeys/p/4058987.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!