Stop service "properly"
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
|
using System.Threading;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Torch.API;
|
using Torch.API;
|
||||||
|
|
||||||
@@ -12,8 +14,8 @@ namespace Torch.Server
|
|||||||
{
|
{
|
||||||
class TorchService : ServiceBase
|
class TorchService : ServiceBase
|
||||||
{
|
{
|
||||||
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
public const string Name = "Torch (SEDS)";
|
public const string Name = "Torch (SEDS)";
|
||||||
private TorchServer _server;
|
|
||||||
private Initializer _initializer;
|
private Initializer _initializer;
|
||||||
private string[] _args;
|
private string[] _args;
|
||||||
|
|
||||||
@@ -42,8 +44,10 @@ namespace Torch.Server
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnStop()
|
protected override void OnStop()
|
||||||
{
|
{
|
||||||
_server.Stop();
|
var mre = new ManualResetEvent(false);
|
||||||
base.OnStop();
|
Task.Run(() => _initializer.Server.Stop());
|
||||||
|
if (!mre.WaitOne(TimeSpan.FromMinutes(1)))
|
||||||
|
Process.GetCurrentProcess().Kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user