gpt4 book ai didi

c# - Topshelf:成功安装服务后安装命令没有返回

转载 作者:太空狗 更新时间:2023-10-29 23:37:39 24 4
gpt4 key购买 nike

注意:我没有做任何类似于 Topshelf installer requires me to press enter twice - why? 的事情

服务类(有趣的部分):

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;
}
}

程序.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

服务安装正常,但命令永远不会返回:

Running a transacted installation.

Beginning the Install phase of the installation. Installing service NotificationEngine.Main... Service NotificationEngine.Main has been successfully installed.

The Install phase completed successfully, and the Commit phase is beginning.

The Commit phase completed successfully.

The transacted install has completed.

^C (I have to press CTRL+C)

安装命令完成并返回应该怎么做?

注意如果我运行帮助(即帮助显示但命令不返回),可以观察到相同的行为:

MyService.exe help

最佳答案

通常这意味着您没有释放对某些资源的控制并且进程无法完全退出。不过这东西比较复杂,不好说。

一些我会尝试的事情

  • 在安装/CTRL+C 后执行 MyService start 会发生什么?我假设它也会阻塞,因为 help 确实如此。
  • 检查日志记录,是否已启用?是否存在文件争用或权限问题?
  • Main() 入口点还有什么作用?它在 host.Run() 之后做了什么吗?上面的代码使它看起来像是从该对象的构造中调用它,但我认为它是错误的剪切粘贴。
  • 确保您没有在 ConstructUsingWhen* 回调被触发之前初始化资源。

在此之后,我会将其发送到我们的邮件列表 https://groups.google.com/forum/#!forum/topshelf-discuss .

关于c# - Topshelf:成功安装服务后安装命令没有返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34939042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com