-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSystemService.cs
45 lines (37 loc) · 1.03 KB
/
SystemService.cs
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
using NetTunnel.Service.TunnelEngine;
namespace NetTunnel.Service
{
internal class SystemService
{
private readonly SemaphoreSlim _semaphoreToRequestStop;
private readonly Thread _thread;
public SystemService()
{
_semaphoreToRequestStop = new SemaphoreSlim(0);
_thread = new Thread(DoWork);
}
public void Start()
{
_thread.Start();
}
public void Stop()
{
_semaphoreToRequestStop.Release();
_thread.Join();
}
private void DoWork()
{
Thread.CurrentThread.Name = $"DoWork:{Environment.CurrentManagedThreadId}";
Singletons.ServiceEngine.Start();
while (true)
{
if (_semaphoreToRequestStop.Wait(500))
{
Singletons.Logger.Verbose("Stopping...");
Singletons.ServiceEngine.Stop();
break;
}
}
}
}
}