blob: da7537cd70a96300c8087f8eebab5a3c919d1a2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
using MediaBrowser.Model.Logging;
using System.Linq;
using System.ServiceProcess;
namespace MediaBrowser.ServerApplication
{
/// <summary>
/// Class BackgroundService
/// </summary>
public class BackgroundService : ServiceBase
{
public static string Name = "Emby";
public static string DisplayName = "Emby Server";
public static string GetExistingServiceName()
{
try
{
if (ServiceController.GetServices().Any(s => s.ServiceName == "MediaBrowser"))
{
return "MediaBrowser";
}
}
catch
{
return "MediaBrowser";
}
return Name;
}
private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="BackgroundService"/> class.
/// </summary>
public BackgroundService(ILogger logger)
{
_logger = logger;
CanPauseAndContinue = false;
CanStop = true;
ServiceName = GetExistingServiceName();
}
/// <summary>
/// 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.
/// </summary>
protected override void OnStop()
{
_logger.Info("Stop command received");
base.OnStop();
}
}
}
|