-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
39 lines (29 loc) · 958 Bytes
/
Program.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
using TelegramBotService;
using Topshelf;
var serviceName = "Sample Telegram Bot";
var serviceDescription = "A sample Telegram bot.";
HostFactory.Run(hostService =>
{
hostService.Service<ServiceBuilder>(svcConfig =>
{
svcConfig.ConstructUsing(_ => new ServiceBuilder());
svcConfig.WhenStarted(service => service.Start(args));
svcConfig.WhenStopped(service => service.Stop());
});
hostService.EnableServiceRecovery(recovery =>
{
recovery.RestartService(0);
recovery.RestartService(1);
recovery.RestartService(1);
});
hostService.SetDescription(serviceDescription);
hostService.SetDisplayName(serviceName);
#if DEBUG
hostService.SetServiceName($"{serviceName}_{Guid.NewGuid():N}");
#else
hostService.SetServiceName(serviceName);
# endif
hostService.EnableShutdown();
hostService.StartAutomaticallyDelayed();
hostService.RunAsNetworkService();
});