简体   繁体   中英

.net core Windows Service vs Worker Template

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 .

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

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.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM