zoukankan      html  css  js  c++  java
  • 服务制作

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Timers;
    
    namespace Rhyhtmk.WindowsService
    {
        /*
         @ blogs:  http://www.cnblogs.com/rhythmk
         */
        public partial class MyServices : ServiceBase
        {
            private System.Timers.Timer timer1 = new System.Timers.Timer();
    
            public MyServices()
            {
                this.timer1.Enabled = true;
                this.timer1.Interval = 1000D;
                this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
                InitializeComponent();
                this.ServiceName = "Rhythmk 测试服务";
    
            }
    
            protected override void OnStart(string[] args)
            {
                this.WriteLog("Rhythmk服务启动正常!");
                this.timer1.Enabled = true;
                this.timer1.Start();
            }
    
            protected override void OnStop()
            {
                this.timer1.Enabled = false;
                this.WriteLog("Rhythmk服务停止服务!");
            }
    
            private void timer1_Tick(object sender, ElapsedEventArgs e)
            {
                this.WriteLog("timer绑定方法被触发!");
            }
    
            #region  记录日志
            private void WriteLog(string msg)
            {
                msg = "Time:" + DateTime.Now.ToString() + "\r\n" + msg;
                string path = @"C:\bin\rhythmk.txt"; 
                StreamWriter sw = File.AppendText(path);
                sw.WriteLine("----------------结果开始----------------");
                sw.WriteLine(msg);
                sw.WriteLine("----------------结果结束----------------");
                sw.Flush();
                sw.Close();
            }
            #endregion
        }
    }
    

    Install.bat:

    sc create RhythmkTask binpath= "%CD%\Rhyhtmk.WindowsService.exe" displayname= "Rhythmk.WindowsService" depend= Tcpip start= auto
    sc description RhythmkTask "Rhythmk任务系统"
    sc start RhythmkTask
    pause

    UnInstall.bat:

    sc stop RhythmkTask
    sc delete RhythmkTask
    pause

  • 相关阅读:
    Apache Pig的前世今生
    openssl之EVP系列之6---EVP_Encrypt系列函数编程架构及样例
    P3388 【模板】割点(割顶)
    让priority_queue支持小根堆的几种方法
    2017.11.7解题报告
    一个例子教你如何与出题人斗智斗勇
    debug
    树上倍增求LCA及例题
    素数的筛法
    Catalan卡特兰数入门
  • 原文地址:https://www.cnblogs.com/rhythmK/p/2724502.html
Copyright © 2011-2022 走看看