BackgroundService.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using MediaBrowser.Model.Logging;
  2. using System.ServiceProcess;
  3. namespace MediaBrowser.ServerApplication
  4. {
  5. /// <summary>
  6. /// Class BackgroundService
  7. /// </summary>
  8. public class BackgroundService : ServiceBase
  9. {
  10. public static string Name = "Emby";
  11. public static string DisplayName = "Emby Server";
  12. public static string GetExistingServiceName()
  13. {
  14. return Name;
  15. }
  16. private readonly ILogger _logger;
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="BackgroundService"/> class.
  19. /// </summary>
  20. public BackgroundService(ILogger logger)
  21. {
  22. _logger = logger;
  23. CanPauseAndContinue = false;
  24. CanStop = true;
  25. ServiceName = GetExistingServiceName();
  26. }
  27. /// <summary>
  28. /// 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.
  29. /// </summary>
  30. protected override void OnStop()
  31. {
  32. _logger.Info("Stop command received");
  33. base.OnStop();
  34. }
  35. }
  36. }