2016-01-22 116 views
3

注意不回:我没有做类似的事情,以Topshelf installer requires me to press enter twice - why?Topshelf:install命令在成功安装服务

服务类(有趣的部分):

public class ServiceCore 
{ 
    public ServiceCore(ServiceRuntimeConfiguration serviceRuntimeConfiguration) 
    { 
     _runningTasks = new List<Task>(); 
    } 

     public bool Start(HostControl hostControl) 
     { 
      _hostControl = hostControl; 
      _messageProcessor.Start(); // Starts a System.Threading.Tasks.Task 
      StartListener(); // starts a System.Threading.Tasks.Task 
      return true; 
     } 
} 

的Program.cs:

Host host = HostFactory.New(configurator => 
{ 

configurator.UseNLog(); 

// Configure core service 
configurator.Service<ServiceCore>(svc => 
{ 
    svc.ConstructUsing(theService => new ServiceCore(_serviceRuntimeConfiguration)); 
    svc.WhenStarted((svc, hostControl) => svc.Start(hostControl)); 
    svc.WhenStopped((svc, hostControl) => svc.Stop(hostControl)); 
}); 

// Configure recovery params 
configurator.EnableServiceRecovery(recoveryConfigurator => 
{ 
    recoveryConfigurator.RestartService(0); 
    recoveryConfigurator.OnCrashOnly(); 
    recoveryConfigurator.SetResetPeriod(1); 
}); 

// Execute HostConfigurator 
host.Run(); 
} 

的问题

当我这样做:

MyService.exe install --manual --localsystem 

服务安装罚款,但该命令不会返回:

运行事务处理安装。

开始安装的安装阶段。安装服务 NotificationEngine.Main ... Service NotificationEngine.Main已成功安装 。

安装阶段成功完成,提交阶段开始时为 。

提交阶段已成功完成。

交易安装已完成。

^C(我必须按CTRL + C)

我应该怎么install命令来完成,然后返回呢?

注意同样的行为是可观察的,如果我跑的帮助(即帮助的显示,但命令不返回):

MyService.exe help 

回答

2

一般来说,这意味着你不释放一些资源和过程控制不能干净地退出。但是,这个东西很复杂,所以很难说清楚。

有几件事情我会尝试

  • 什么,当你的安装/ CTRL + C后执行MyService start发生什么呢?我假设它也会阻止帮助。
  • 检查日志记录,你有任何启用?是否存在文件争用或权限问题?
  • 您的Main()入口点还有什么作用?是否在host.Run()之后做了些什么?上面的代码使得它看起来像是从该对象的构造中调用它,但我认为它是不好的剪切粘贴。
  • 确保您在启动ConstructUsingWhen*回调之前未初始化资源。

在此之后,我会把它带到我们的邮件列表https://groups.google.com/forum/#!forum/topshelf-discuss

+0

感谢您的精心解答。我会检查并回复。 – dotnetguy

相关问题