windows 服务

 

 

windows 服务

 

windows 服务

 

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.IO;

namespace WindowsService2
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
FileStream fs = new FileStream(@"d:\xx.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine("WindowsService: Service Started" + DateTime.Now.ToString() + "\n");

sw.Flush();
sw.Close();
fs.Close();
}

protected override void OnStop()
{
FileStream fs = new FileStream(@"d:\xx.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine("WindowsService: Service Stopped" + DateTime.Now.ToString() + "\n");
sw.Flush();
sw.Close();
fs.Close();
}
}
}

windows 服务

 

生成 项目 

InstallUtil.exe  把 它 复制 项目debug 下

windows 服务

windows 服务windows 服务

 

windows 服务

windows 服务

 

windows 服务

上一篇:Prometheus监控概述&部署


下一篇:winform关于AcceptButton和CanceleButton的问题