c# windows service(服务)

//安装
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe WindowsServiceTest.exe
//卸载
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u WindowsServiceTest.exe

具体步骤参考:

http://www.cnblogs.com/sorex/archive/2012/05/16/2502001.html

 

死循环的程序:

  protected override void OnStart(string[] args)
        {
            Task.Run(()=> { run(); });

        }
        public void run()
        {
            while (true)
            {
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter("C:\\log.txt", true))
                {
                    sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "Start.");
                }
                Thread.Sleep(2000);
            }
        }

 

@echo off
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe "%~dp0\DeLoadServer.exe"
echo "安装成功"
Net Start DeLoadServer
sc config DeLoadServer start= auto
pause

 

posted @ 2017-04-21 14:28  小小高  阅读(293)  评论(0)    收藏  举报