-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathTorchService.cs
More file actions
57 lines (51 loc) · 1.55 KB
/
TorchService.cs
File metadata and controls
57 lines (51 loc) · 1.55 KB
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceProcess;
using System.Threading;
using NLog;
using Torch.API;
namespace Torch.Server
{
class TorchService : ServiceBase
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public const string Name = "Torch (SEDS)";
private Initializer _initializer;
private string[] _args;
public TorchService(string[] args)
{
_args = args;
var workingDir = new FileInfo(typeof(TorchService).Assembly.Location).Directory.ToString();
Directory.SetCurrentDirectory(workingDir);
_initializer = new Initializer(workingDir);
ServiceName = Name;
CanHandleSessionChangeEvent = false;
CanPauseAndContinue = false;
CanStop = true;
}
/// <inheritdoc />
protected override void OnStart(string[] _)
{
base.OnStart(_args);
_initializer.Initialize(_args);
_initializer.Run();
}
/// <inheritdoc />
protected override void OnStop()
{
var mre = new ManualResetEvent(false);
Task.Run(() =>
{
_initializer.Server.Stop();
_initializer.Server.Destroy();
});
if (!mre.WaitOne(TimeSpan.FromMinutes(1)))
Process.GetCurrentProcess().Kill();
}
}
}