Earn More by Sharing What You Love
Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!

Tim Corey
31m 20s
Windows services are powerful tools in the .NET ecosystem, capable of performing background tasks without user intervention. Creating a Windows service in C# can sound complex, but in his video "Intro to Windows Services in C# - How to create, install, and use a service using Topshelf," Tim Corey breaks it down step-by-step.
In this article, we'll walk through that video, covering each topic to provide clarity and continuity.
Tim introduces Windows services as powerful, often-overlooked tools for automation. These applications are designed to run in the background, handling tasks without needing a user interface. Common examples include the SQL Server Agent or Hyper-V services.
Tim emphasizes the importance of practice for mastering C#. He recommends downloading the source code linked in the video description for hands-on learning.
Using Visual Studio, Tim creates a new console application project called SimpleHeartbeatService. Although you could use a Windows Service project template, Tim prefers the console approach for debugging simplicity.
"The idea here is not about what code I put in here, but instead on how to create the service itself," Tim notes.
Tim opens the Services tab in Windows using the Start menu search (just type "services" and press Enter). He explains that services running in the background perform vital operating system functions like remote desktop or MySQL server.
The goal is to create a new entry in this list using custom code.
You might be tempted to select the Windows Service project in Visual Studio, but Tim explains it's harder to debug. Instead, a console app lets you run and test it locally, reducing the need to attach a debugger to a live service.
"The built-in service type project makes debugging harder because you have to install it first, then attach a debugger."
To simplify the service implementation, Tim adds Topshelf, an open-source framework, via NuGet. This popular library (with millions of downloads) helps create Windows services without boilerplate code.
Steps:
Tim creates a Heartbeat class with two public methods: Start() and Stop(). Inside the constructor, he sets up a System.Timers.Timer to execute every second.
This timer's Elapsed event appends the current time to a .txt file in the C:\temp\demos\ folder. This mimics a background task that runs continuously.
"This timer will write to a text file every second, showing that the service is alive."
This simulates how long-running processes work in real services, like folder scanning or printing documents.
Using HostFactory.Run, Tim integrates Topshelf into the application:
He also sets metadata for the service:
Before installation, Tim runs the application to test it. The timer correctly appends timestamps to heartbeat.txt. Using Notepad++'s Monitoring feature, he shows real-time updates.
Tim copies the .exe and related files from the bin\Debug folder to a permanent location (like C:\demos\HeartbeatService). Using an administrative command prompt, he runs the following commands:
SimpleHeartbeatService.exe install
SimpleHeartbeatService.exe startSimpleHeartbeatService.exe install
SimpleHeartbeatService.exe startThis adds the service to the Service Control Manager. Opening the Services tab again and clicking Refresh, the service is now visible and running.
"It's really easy to install a service, and it's really easy to do things with a service."
To uninstall:
SimpleHeartbeatService.exe uninstallSimpleHeartbeatService.exe uninstallTim recaps that creating and installing a service using Topshelf is straightforward. However, he warns that infinite file writing can lead to storage issues, which is a good reminder for proper log management.
Tim shares practical ideas for Windows services:
These examples show how to use services to automate background tasks and integrate with tools like SQL Server, OneDrive, and task schedulers.
Tim concludes by encouraging developers to experiment. Just be careful with memory, storage, and event logging. If you need auto-update, security settings, or more robust deployment, further configuration will be required.
"There's a lot of power here, and a lot of stuff you can do."
Using Tim Corey's step-by-step demonstration in his video, creating a Windows service in C# becomes accessible and practical. By leveraging Topshelf, a console application can be converted into a fully functioning Windows service with minimal setup. Whether you're managing log files, handling database events, or performing automation, services offer a powerful and scalable way to build real-time, background .NET Framework or .NET Core applications.
Use this tutorial as your full path to understanding, creating, and installing services efficiently. Don't forget to test thoroughly and always run the installer or command prompt as an administrator.
Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!
Join our newsletter, you’ll get exclusive access on article updates. We value your privacy