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

  • 相关阅读:
    向modesim中添加alter库 (或者在每次仿真时将库文件加入仿真文件夹一起编译)
    分布式文件系统FastDFS
    Redisson实现分布式锁
    redis分布式锁
    redis 安装与集群
    linux 关闭防火墙
    linux 安装Tomcat
    linux yum 方式安装jdk8
    linux 下安装 Nginx
    Centos7 yum时,出现could not retrieve mirrorlist问题
  • 原文地址:https://www.cnblogs.com/rhythmK/p/2724502.html
Copyright © 2011-2022 走看看