aspnet / Hosting

[Archived] Code for hosting and starting up an ASP.NET Core application. Project moved to https://github.com/aspnet/Extensions and https://github.com/aspnet/AspNetCore
Apache License 2.0
552 stars 312 forks source link

Question: RunAsService for non web-apps #1529

Closed johnkors closed 6 years ago

johnkors commented 6 years ago

Hi,

What would be the equivalent of host.RunAsService() for regular .NET Core (non-web, no ASP.NET Core/Kestrel)-apps..?

Do you have minimal sample of a host that does this? All samples I've seen are centered around hosting ASP.NET Core as a Windows Service, but I only want a IHostedService to run background tasks - no Kestrel or WebHosts needed.

khellang commented 6 years ago

See https://github.com/aspnet/Hosting/blob/master/samples/GenericHostSample/ServiceBaseControlled.cs

johnkors commented 6 years ago

Thanks!

johnkors commented 6 years ago

So to get this part running, I'd need to implement the the ServiceBaseLiftetime as in the sample ? Any reason for it not being part of a NuGet somewhere instead of the samples..?

davidfowl commented 6 years ago

Because we haven't gotten to that part yet 😄

johnkors commented 6 years ago

Hah. Fair enough. 😸

johnkors commented 6 years ago

Shipped it as a NuGet until you get it in .NET Core.

https://github.com/icenorge/DotNetCore.WindowsServices/ https://www.nuget.org/packages/DotNetCore.WindowsServices/

Hope that's ok.