© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
226 replies
júlio

❔ Windows BackgroundService

Hello. So I'm a beginner at C# and a beginner and making services, so I'm not sure how stupid some one the questions I'm about to ask might sound. Regardless I would really appreciate if someone could either explain me things or link to useful documentation.
I have the following questions regarding Windows Services in C#:

1- From my understanding, the flow of the Service goes as follows (I'll be referring to
BackgroundServices
BackgroundServices
, since that is what the documentation advice me to use, apparently it's the modern approach to making a Service in Windows):
In the
Program.cs
Program.cs
file, we have a
builder
builder
, we give the
builder 
builder 
information about the classes that are going to do tasks (?) and then we tell it to
.Run()
.Run()
. So I assume this is the code that will run when in the shell I do
sc.exe create <service_name.exe>
sc.exe create <service_name.exe>
. Please correct me If I'm wrong. Then I need to start the service so that it starts doing the thing I tell it to do, and I would stop it if I wanted to stop the service. To kill the service I would need to delete it. This would all be done using the
sc.exe
sc.exe
.

2- Still regarding
Program.cs
Program.cs
, what is a
HostApplicationBuilder
HostApplicationBuilder
, and why do I need one? The documentation that I followed (https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service) used a bunch of
Host
Host
stuff in the
Program.cs
Program.cs
file but didn't really explained what was going on, so this is my biggest question mark so far, is what is going on with the
Program.cs
Program.cs
file.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

BackgroundService Question
C#CC# / help
11mo ago
✅ BackgroundService blocking on Startup
C#CC# / help
3mo ago
BackgroundService and dbcontext memory issue
C#CC# / help
2y ago
❔ How to restart a BackgroundService
C#CC# / help
3y ago