-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleService.cs
More file actions
55 lines (39 loc) · 1.2 KB
/
Copy pathExampleService.cs
File metadata and controls
55 lines (39 loc) · 1.2 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
using System;
using System.Threading.Tasks;
using Topshelf;
namespace TopshelfSample.Service
{
internal class ExampleService : ServiceControl
{
private readonly Task _task;
private HostControl _hostControl;
public ExampleService()
{
_task = new Task(DoWork);
}
private void DoWork()
{
Console.WriteLine("Listen very carefully, I shall say this only once.");
_hostControl.Stop();
}
public void Start() { }
public void Stop() { }
public void Pause() { }
public void Continue() { }
public void Shutdown() { }
public Boolean Start(HostControl hostControl)
{
// So we can stop the service at the end of the check.
this._hostControl = hostControl;
// Start the DoWork thread.
this._task.Start();
// If the task takes longer than expected then request more time to start the service.
this._hostControl.RequestAdditionalTime(new TimeSpan(1));
return true;
}
public Boolean Stop(HostControl hostControl)
{
return true;
}
}
}