title: Email me if windows service stops
body: <p>I want to be able to check if a certain service is running (say it had a Display name - ServiceA).  I want my program to check say every 5 mins that the service is still running.  If it is fine, it will loop and wait another 5 mins and then check again.  If it finds that ServiceA has stopped I want the program to email me and say...ServiceA has stopped running.  Below I have the code which I have done so far which is able to pull all the current services running and there actual display name back to the console.  Anyone any ideas on the code/logic needed for what I need above?</p>
  
  <pre><code>namespace ServicesChecker
  {
      class Program
      {
          static void Main(string[] args)
          {
              ServiceController[] scServices;
              scServices = ServiceController.GetServices();
  
              Console.WriteLine("Services running on the local computer:");
              foreach (ServiceController scTemp in scServices)
              {
                  if (scTemp.Status == ServiceControllerStatus.Running)
                  {
                      Console.WriteLine();
                      Console.WriteLine("  Service :        {0}", scTemp.ServiceName);
                      Console.WriteLine("    Display name:    {0}", scTemp.DisplayName); 
                  }
              }
              //Create a Pause....
              Console.ReadLine();
          }
      }
  }
  </code></pre>