Windows Forms: How to check Windows Service Status in C#
By FoxLearn 9/3/2020 5:03:29 AM 3.91K
This post show you How to check Windows Service Status in C#
Sometimes you may need to check the status of windows service, you can do it with following simple way.
Creating a new Windows Forms Application, then design a simple UI as shown below. You can also use console application to run the code below.
Right-clicking on your Reference, then add System.ServiceProcess to your project.
Adding a click event handler to the check button allows you to check the windows service status.
private void btnCheck_Click(object sender, EventArgs e) { var service = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == txtServiceName.Text); if (service == null) lblStatus.Text = $"Service {txtServiceName.Text} not found!"; else lblStatus.Text = $"Service {txtServiceName.Text} is {service.Status}"; }
and don't forget to add
using System.ServiceProcess;
to your form.
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024
What Are RESTful Web Services?
02/19/2024