You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB
C#

10 months ago
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
namespace DSWeb.Service.Output
{
class Program
{
static void Main(string[] args)
{
var serviceName = ConfigurationManager.AppSettings["ServiceName"];
var serviceDisplayName = ConfigurationManager.AppSettings["ServiceDisplayName"];
if (Environment.UserInteractive)
{
Console.Title = serviceDisplayName;
}
Host host = HostFactory.New(x =>
{
// 基本的配置
x.RunAsLocalSystem();
x.SetServiceName(serviceName);
x.SetDisplayName(serviceDisplayName);
x.StartAutomaticallyDelayed();
x.EnableShutdown();
// 注册服务
x.Service(hostSettings => new OutputJobService());
// 设置服务失败后的操作,分别对应第一次、第二次、后续
x.EnableServiceRecovery(t =>
{
t.RestartService(0);
t.RestartService(0);
t.RestartService(0);
t.OnCrashOnly();
});
});
host.Run();
}
}
}