-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
101 lines (84 loc) · 3.43 KB
/
Copy pathProgram.cs
File metadata and controls
101 lines (84 loc) · 3.43 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Quartz;
using System;
using System.Timers;
using Topshelf;
using Topshelf.Quartz;
using TopshelfSample.Service;
namespace TopshelfSample
{
internal class Program
{
private static void Main(string[] args)
{
var host1TopshelfOnly = HostFactory.Run(host1Config =>
{
host1Config.Service<ExampleService>(service1Config =>
{
service1Config.ConstructUsing(service => new ExampleService());
service1Config.WhenStarted(s => s.Start());
service1Config.WhenStarted((s, hostControl) => s.Start(hostControl));
service1Config.WhenStopped(s => s.Stop());
service1Config.WhenStopped((s, hostControl) => s.Stop(hostControl));
service1Config.WhenPaused(s => s.Pause());
service1Config.WhenContinued(s => s.Continue());
service1Config.WhenShutdown(s => s.Shutdown());
});
host1Config.RunAsLocalSystem();
host1Config.SetServiceName("ExampleService");
});
var host2TOpshelfWithQuartz = HostFactory.Run(host2Config =>
{
host2Config.Service<TownCrier>(service2Config =>
{
service2Config.ConstructUsing(name => new TownCrier());
service2Config.WhenStarted(tc => tc.Start());
service2Config.WhenStopped(tc => tc.Stop());
service2Config.ScheduleQuartzJob<TownCrier>(q =>
q.WithJob(() =>
JobBuilder.Create<ExampleJob>().Build())
.AddTrigger(() =>
TriggerBuilder.Create().WithIdentity(new TriggerKey("Name", "Group"))
.WithSimpleSchedule(builder => builder
.WithIntervalInSeconds(20)
.RepeatForever())
.Build())
);
service2Config.ScheduleQuartzJob<TownCrier>(q =>
q.WithJob(() =>
JobBuilder.Create<ExampleJob>().Build())
.AddTrigger(() =>
TriggerBuilder.Create().WithIdentity(new TriggerKey("Name", "Group"))
.WithSimpleSchedule(builder => builder
.WithIntervalInSeconds(60)
.RepeatForever())
.Build())
);
});
host2Config.RunAsLocalSystem();
host2Config.SetServiceName("Stuff");
host2Config.SetDisplayName("Stuff");
host2Config.SetDescription("Sample Topshelf Host");
});
}
}
internal class TownCrier
{
private readonly Timer _timer;
public TownCrier()
{
_timer = new Timer(1000) { AutoReset = true };
_timer.Elapsed +=
(sender, eventArgs) =>
Console.WriteLine("It is {0} and all is well. By the way, it's time to go get your license.",
DateTime.Now);
}
public void Start()
{
_timer.Start();
}
public void Stop()
{
_timer.Stop();
}
}
}