在.NET Core中编写Windows服务 [英] Writing windows service in .net core

查看:342
本文介绍了在.NET Core中编写Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何在以前使用.net版本编写的.net核心中编写Windows服务?

My question is How can I write the windows service in .net core which we used to write in prior .net versions ?

很多链接/文章介绍了如何将您的.net核心应用程序托管为Windows服务。所以这是我创建Windows服务的唯一方法吗?

Lots of links/articles explain how to host your .net core application as windows service. So this is the only way I can create windows service ?

如果是,请问任何人都可以提供它的链接/示例

If yes, can anyone please provide the links/example of it

谢谢!

推荐答案

不确定是否有默认的方法。但是,您可以让您的核心应用程序继承自 ServiceBase 并实现必要的替代。我们在应用程序中执行此操作(请注意,我们针对的是完整框架,而不是核心)。最初的想法来自以下文章:

Not sure if there is a default way of doing this. You can however let your core application inherit from ServiceBase and implement the necessary overrides. We do this in our application (note that we target the full framework, not core). The original idea for this came from the following articles:

  • How to Run DNX Applications in a Windows Service
  • How to Host ASP.NET in a Windows Service
  • This question also references the same articles.

请注意,这些文章仍引用 DNX (从.NET Core测试版开始)-这些天,您的核心应用程序将编译为exe,因此您可以调整其示例以适应这一需求。

Note that these articles still reference DNX (from the .NET Core beta days) - these days your core app will compile to an exe, so you can adjust their examples to cater for that.

这篇关于在.NET Core中编写Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆