Topshelf 没有达到 OnStart 方法
Topshelf not hitting OnStart Method
我正在尝试构建我的第一个基于顶层的服务。我正在尝试遵循快速入门中的模式 http://docs.topshelf-project.com/en/latest/configuration/quickstart.html
static void Main(string[] args)
{
var h = HostFactory.Run(x =>
{
ConfHost(x);
});
}
private static void ConfHost (Topshelf.HostConfigurators.HostConfigurator x )
{
x.Service<JobRunner>(s =>
{
ConfService(s);
});
x.RunAsLocalSystem();
x.StartAutomatically();
x.SetDescription("topshelf thing");
x.SetDisplayName("displayname ");
x.SetServiceName("svc name");
}
private static void ConfService(ServiceConfigurator<JobRunner> s)
{
s.ConstructUsing(name => new JobRunner());
s.WhenStarted(bt => bt.OnStart());
s.WhenStopped(bt => bt.OnStop());
}
此代码直接运行并终止,即使我在第一行放置了一个断点,也没有碰到 JobRunner 上的 Onstart 方法。
希望其他人能从我的错误中吸取教训,控制台输出实际上给出了你需要仔细检查或在最后放一个 Console.Read() 才能看到的原因
ConfigurationException: The service was not properly configured:
[Failure] Name must not contain whitespace, '/' or '\' characters
Windows 支持服务名称中的 spaces:
x.SetDisplayName("displayname "); //这里是space
在没有 spaces 的情况下将其更改为另一个值并且必须有效...
我正在尝试构建我的第一个基于顶层的服务。我正在尝试遵循快速入门中的模式 http://docs.topshelf-project.com/en/latest/configuration/quickstart.html
static void Main(string[] args)
{
var h = HostFactory.Run(x =>
{
ConfHost(x);
});
}
private static void ConfHost (Topshelf.HostConfigurators.HostConfigurator x )
{
x.Service<JobRunner>(s =>
{
ConfService(s);
});
x.RunAsLocalSystem();
x.StartAutomatically();
x.SetDescription("topshelf thing");
x.SetDisplayName("displayname ");
x.SetServiceName("svc name");
}
private static void ConfService(ServiceConfigurator<JobRunner> s)
{
s.ConstructUsing(name => new JobRunner());
s.WhenStarted(bt => bt.OnStart());
s.WhenStopped(bt => bt.OnStop());
}
此代码直接运行并终止,即使我在第一行放置了一个断点,也没有碰到 JobRunner 上的 Onstart 方法。
希望其他人能从我的错误中吸取教训,控制台输出实际上给出了你需要仔细检查或在最后放一个 Console.Read() 才能看到的原因
ConfigurationException: The service was not properly configured: [Failure] Name must not contain whitespace, '/' or '\' characters
Windows 支持服务名称中的 spaces:
x.SetDisplayName("displayname "); //这里是space
在没有 spaces 的情况下将其更改为另一个值并且必须有效...