简体   繁体   English

我可以在 dot net core 控制台应用程序中使用 BackgroundService

[英]Can I use BackgroundService in dot net core console application

I know how to use background service in asp.net core我知道如何在asp.net core中使用后台服务

public class WatchMan : BackgroundService
{
    
}

I have a dot core console application which I want to run as window service, can I use BackgroundService or something similar there?我有一个 dot core 控制台应用程序,我想将它作为窗口服务运行,我可以在那里使用BackgroundService或类似的东西吗?

Yes, just be sure to keep the main thread alive so the application does not exit.是的,只要确保主线程保持活动状态,应用程序就不会退出。

This article seems to explain the process decently;这篇文章似乎很好地解释了这个过程; https://medium.com/@daniel.sagita/backgroundservice-for-a-long-running-work-3debe8f8d25b https://medium.com/@daniel.sagita/backgroundservice-for-a-long-running-work-3debe8f8d25b

And here's an SO that shows the process aswell:这是一个显示该过程的 SO:

Trigger background service ExecuteAsync method in .Net core console application 在.Net核心控制台应用程序中触发后台服务ExecuteAsync方法

Also if you want to do some background processing, take a look at hangfire:另外如果你想做一些后台处理,看看hangfire:

https://www.hangfire.io/ https://www.hangfire.io/

Which can also be ran from a windows service.也可以从 Windows 服务运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ASP.NET 核心应用程序中使用 BackgroundService 每年执行一个方法? - How can I execute a method every year using BackgroundService in ASP.NET core Application? 我怎样才能端到端地测试这个 .net 核心控制台应用程序? - How can I end to end test this .net core console application? 如何在控制台上验证dot net应用程序配置文件(例如,app.exe.config)? - how can I validate dot net application config file(ex, app.exe.config) on console? 是否可以在.Net Core 2控制台应用程序中使用WCF? - Is it possible to use WCF in a .Net Core 2 console application? 如何在Dot Net Core中为第三方静态类使用DI? - How can I use DI for 3'rd party static class in Dot Net Core? 在 .net 核心 3.0 BackgroundService 应用程序中,为什么我的配置 object 作为服务运行时为空,而不是作为控制台应用程序运行? - In a .net core 3.0 BackgroundService app, why is my configuration object empty when running as service, but not as console app? 我可以在wpf应用程序中使用网络核心库吗? - Can I use a net core library in a wpf application? 几天后 dot net core 控制台应用程序自动停止工作 - Dot net core console application stops working automatically after few days 我如何在 dot net Core 中安排应用程序 dll 文件 - How can i Arrange app dll files in dot net Core 为点网(不是点网核心)应用程序创建 Dockerfile - Create a Dockerfile for a dot net (not dot net core) application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM