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.

46 lines
1.3 KiB
C#

5 years ago
using System;
using Topshelf;
using System.Security.Cryptography.X509Certificates;
5 years ago
using System.Threading.Tasks;
5 years ago
namespace TopshelfStudy.NetCoreDemo
{
class Program
{
5 years ago
static async Task Main(string[] args)
5 years ago
{
var topshelfExitCode = HostFactory.Run(config =>
{
//使用NLog日志
config.UseNLog(NLog.LogManager.LogFactory);
//服务配置
config.Service<TopshelfService>(s =>
{
s.ConstructUsing(name => new TopshelfService());
s.WhenStarted(tc => tc.Start());
s.WhenStopped(tc => tc.Stop());
});
//运行服务帐户
config.RunAsLocalSystem();
//服务名(所有服务中唯一)
config.SetServiceName("AIoT.Service.Demo");
//服务显示名
config.SetDisplayName("AIoT服务测试");
//服务描述
config.SetDescription("这是一个AIoT服务测试例子使用Topshelf类库方便调试");
});
//退出码
Environment.ExitCode = (int)Convert.ChangeType(topshelfExitCode, topshelfExitCode.GetTypeCode());
5 years ago
await Task.CompletedTask;
5 years ago
}
}
}