简体   繁体   中英

Can I use BackgroundService in dot net core console application

I know how to use background service in 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?

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

And here's an SO that shows the process aswell:

Trigger background service ExecuteAsync method in .Net core console application

Also if you want to do some background processing, take a look at hangfire:

https://www.hangfire.io/

Which can also be ran from a windows service.

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