的ServiceController似乎无法停止
我想在本地机器上停止Windows服务的服务(该服务是Topshelf.Host
,如果该事项)使用此代码:的ServiceController似乎无法停止
serviceController.Stop();
serviceController.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
timeout
设为1小时,但服务从未实际停止。奇怪的是,从服务MMC管理单元中,我首先看到它处于“停止”状态,但过了一段时间,它又恢复为“已启动”。但是,当我尝试手动停止它时,发生错误:
Windows could not stop the Topshelf.Host service on Local Computer.
Error 1061: The service cannot accept control messages at this time.
我在这里丢失了什么吗?
我也看到过这个问题,特别是当一个服务开始等待时,我发送它停止以编程方式成功,但什么都不做。有时候我也会看到停止命令对于正在运行的服务会失败,但是同样的异常仍然会停止服务。我不认为API可以被信任去做它所说的。此错误消息的解释是非常有帮助...
而从旧的多分区框移动代码到一个新的单个分区箱我只是打了这个问题。在服务停止时,我正在给D写信,因为它不再存在,所以我得到了1061错误。在OnStop期间的任何长操作都会导致这种情况,除非您使用回调代理将呼叫转移到另一个线程。
您的服务正在忙于处理某些大型操作或正在转换以更改状态。因此不能接受了输入...只是把它作为录取比它可以嚼...
,如果你确信你没有什么喂大的吧,只是去任务管理器,关闭此服务的进程或重新启动您的机器。
我所面临的类似issue.This错误有时会发生,因为该服务可以不再接受控制消息,这可能是由于在该特定服务的日志文件存在于服务器磁盘空间问题。 如果发生这种情况,您也可以考虑下面的选项。 1.转到它的日志文件所在的服务exe文件&的位置。 2.释放一些空间 3.通过任务管理器杀死服务进程 4.启动服务。
我知道我很晚回答这个问题,但是我遇到了类似的问题,即错误:“此服务无法接受控制消息。”,并希望将其添加为其他人的参考。
您可以尝试杀死使用PowerShell(PowerShell的运行作为管理员)此服务:
#Get the PID of the required service with the help of the service name, say, service name.
$ServicePID = (get-wmiobject win32_service | where { $_.name -eq 'service name'}).processID
#Now with this PID, you can kill the service
taskkill /f /pid $ServicePID
我有完全一样的问题Topshelf托管服务。原因是服务启动时间长,超过20秒。这使服务处于无法处理进一步请求的状态。 我能够重现只有当问题被服务从命令行(NET START my_service)开始。
与长星时间Topshelf服务正确初始化以下内容:
namespace Example.My.Service
{
using System;
using System.Threading.Tasks;
using Topshelf;
internal class Program
{
public static void Main()
{
HostFactory.Run(
x =>
{
x.Service<MyService>(
s =>
{
MyService testServerService = null;
s.ConstructUsing(name => testServerService = new MyService());
s.WhenStarted(service => service.Start());
s.WhenStopped(service => service.Stop());
s.AfterStartingService(
context =>
{
if (testServerService == null)
{
throw new InvalidOperationException("Service not created yet.");
}
testServerService.AfterStart(context);
});
});
x.SetServiceName("my_service");
});
}
}
public sealed class MyService
{
private Task starting;
public void Start()
{
this.starting = Task.Run(() => InitializeService());
}
private void InitializeService()
{
// TODO: Provide service initialization code.
}
[CLSCompliant(false)]
public void AfterStart(HostControl hostStartedContext)
{
if (hostStartedContext == null)
{
throw new ArgumentNullException(nameof(hostStartedContext));
}
if (this.starting == null)
{
throw new InvalidOperationException("Service start was not initiated.");
}
while (!this.starting.Wait(TimeSpan.FromSeconds(7)))
{
hostStartedContext.RequestAdditionalTime(TimeSpan.FromSeconds(10));
}
}
public void Stop()
{
// TODO: Provide service shutdown code.
}
}
}
谢谢你,这是一个好 – user584018 2017-06-08 11:03:45
使用任务管理器作为管理员,我可以不杀该服务,重启没有帮助。这是为我工作的方法。 – ChrisG 2017-08-18 11:36:17
为我工作。不要忘记以管理员身份运行PowerShell。 – Aaron 2017-10-13 23:03:56