admin 管理员组

文章数量: 1184232

我们知道 core支持console和web开发,分别叫做 core程序和asp core. 

查询 core官方文档,并没有介绍编写windows service相关的说明,一直以来以为dotnet core不支持windows service开发,知道查看asp core部署文档中提到可以部署在Windows service中,从而确定dotnet是可以开发Windows service的.

查看asp core的Windows宿主的源代码Microsoft.AspNetCore.Hosting.WindowsServices,发现最终给宿主是继承自System.ServiceProcess.ServiceBase,同时实现了OnStart以及OnStop等一些列方法.我们知道dotnet framework 中的service基类也是System.ServiceProcess.ServiceBase,所以可以试下按照传统的dotnet framework的方法尝试开发Windowsservice.

 

我们新建一个dotnet console程序,添加一个windows服务,取名WinService

默认代码如下:

using System;
using System.Collections.Generic;
using System.

本文标签: NET core Windows