.net core Windows Service vs Worker 模板 [英] .net core Windows Service vs Worker Template

查看:22
本文介绍了.net core Windows Service vs Worker 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是 这个问题的延续.我只是想了解使用 ServiceBase 类编写的 Windows 服务之间的区别,例如 这篇文章 和使用 WorkerTemplate 的 Windows 服务,完成 此处.

This question is in continuation with this SO question. I just wanted to understand the differences between a Windows Service that is written using ServiceBase class like in this post and a windows service using a WorkerTemplate, done here.

这个问题的原因是前一个实现是在 docker 上工作的,而后一个不是.

The reason for this question is that the former implementation is working on docker and the later is not.

如果我理解正确,WorkerTemplate 是一种尝试,通过提供 将在 StartAsync() 上提供抽象 ExecuteAsync() 并通过将 IHostingLifetime 替换为AddHostedService().那么为什么当我使用 ServiceBase 和 IHostingLifetime 运行应用程序时,它在容器中运行良好,而当我使用 WorkerTemplate 时,它​​会引发服务超时错误.

If I understood correctly WorkerTemplate is an attempt to make, development of windows service easier by providing a package that would provide an abstraction ExecuteAsync() over StartAsync() and managing the lifetime of service by replacing IHostingLifetime with AddHostedService<>(). Then why is it that when I run the application with ServiceBase and IHostingLifetime it works fine in a container and when I use WorkerTemplate it throws me a service timeout error.

注意:这两种实现在本地以及部署在服务器上时都可以正常工作.此行为仅在容器中观察到.

Note: Both the implementations are working fine locally as well as when deployed on servers. This behavior is observed in containers only.

推荐答案

在我看来,第一个是用来托管 asp.net core 应用程序作为 windows 服务的.第二个是将应用程序作为 Web 应用程序托管.

In my opinion, the first is used to host the asp.net core application as the windows service. The second one is host the application as a web application.

这是运行工作服务的两种方式之间的主要区别.asp.net 核心工作者服务是相同的.当 asp.net core 应用程序启动时,asp.net core 将运行工作服务.

This is the main difference between two ways to run the worker service. The asp.net core worker service is the same one. The asp.net core will run the work service when the asp.net core application start.

容器无法运行 windows 服务,但可以运行 asp.net 核心应用程序.

The container couldn't run the windows service but could run the asp.net core application.

这篇关于.net core Windows Service vs Worker 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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