×

# C# .NET平台开发windows 服务程序

hqy hqy 发表于2026-04-08 16:53:38 浏览5 评论0

抢沙发发表评论

# C# .NET平台开发windows 服务程序

开发windows服务程序,以使用 sc create 命令来安装服务

安装包

创建一个 net7 net8 控制台程序,NuGet安装以下包

C#
System.ServiceProcess.ServiceController

创建服务启动代码

C#
partial class MyService : ServiceBase{    public MyService(string[] args)    {        InitializeComponent();    }    protected override void OnStart(string[] args)    {    }    protected override void OnStop()    {    }}

程序入口

C#
internal class Program{    static void Main(string[] args)    {        ServiceBase[] ServicesToRun;        ServicesToRun = new ServiceBase[]        {            new MyService(args)        };        ServiceBase.Run(ServicesToRun);    }}


打赏

本文链接:https://kinber.cn/post/6395.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客