How to stop running service

Dani_S 3,786 Reputation points
2024-04-08T07:39:56.9033333+00:00

Hi,

I have worker service that run quartz sceduler.

The question regard to service.

When quartz sceduler is running and for example there is no space in disk i want to stop the service.

Is it possible if yes please give sample code ?

Thanks,

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,867 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Dani_S 3,786 Reputation points
    2024-04-08T10:58:57.87+00:00
      public static void StopService(string servicName)
    
      {
    
          try
    
          {
    
              ServiceController service = new ServiceController(servicName);
    
              service.Stop();
    
              service.WaitForStatus(ServiceControllerStatus.Stopped);
    
          }
    
          catch (Exception ex)
    
          {
    
              _logger.Error("StopService", ex);
    
          }
    
      }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.