BackgroundService.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using MediaBrowser.Model.Logging;
  2. using System.Linq;
  3. using System.ServiceProcess;
  4. namespace MediaBrowser.ServerApplication
  5. {
  6. /// <summary>
  7. /// Class BackgroundService
  8. /// </summary>
  9. public class BackgroundService : ServiceBase
  10. {
  11. public static string Name = "Emby";
  12. public static string DisplayName = "Emby Server";
  13. public static string GetExistingServiceName()
  14. {
  15. return Name;
  16. }
  17. private readonly ILogger _logger;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="BackgroundService"/> class.
  20. /// </summary>
  21. public BackgroundService(ILogger logger)
  22. {
  23. _logger = logger;
  24. CanPauseAndContinue = false;
  25. CanStop = true;
  26. ServiceName = GetExistingServiceName();
  27. }
  28. /// <summary>
  29. /// When implemented in a derived class, executes when a Stop command is sent to the service by the Service Control Manager (SCM). Specifies actions to take when a service stops running.
  30. /// </summary>
  31. protected override void OnStop()
  32. {
  33. _logger.Info("Stop command received");
  34. base.OnStop();
  35. }
  36. }
  37. }