From 2e511fba839e86d9393e5eeb10795f1b0aed7ce0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Sep 2013 21:04:14 -0400 Subject: support run as service --- .../BackgroundService.cs | 40 ++++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'MediaBrowser.ServerApplication/BackgroundService.cs') diff --git a/MediaBrowser.ServerApplication/BackgroundService.cs b/MediaBrowser.ServerApplication/BackgroundService.cs index a8a9a5b50..019a11e1c 100644 --- a/MediaBrowser.ServerApplication/BackgroundService.cs +++ b/MediaBrowser.ServerApplication/BackgroundService.cs @@ -1,30 +1,40 @@ -using System.ServiceProcess; +using MediaBrowser.Model.Logging; +using System.ServiceProcess; namespace MediaBrowser.ServerApplication { + /// + /// Class BackgroundService + /// public class BackgroundService : ServiceBase { - public BackgroundService() + public static string Name = "MediaBrowser"; + public static string DisplayName = "Media Browser"; + + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + public BackgroundService(ILogger logger) { + _logger = logger; + CanPauseAndContinue = false; - CanHandleSessionChangeEvent = true; - CanStop = false; - CanShutdown = true; - ServiceName = "Media Browser"; - } - protected override void OnSessionChange(SessionChangeDescription changeDescription) - { - base.OnSessionChange(changeDescription); - } + CanStop = true; - protected override void OnStart(string[] args) - { + ServiceName = Name; } - protected override void OnShutdown() + /// + /// 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. + /// + protected override void OnStop() { - base.OnShutdown(); + _logger.Info("Stop command received"); + + base.OnStop(); } } } -- cgit v1.2.3