[英]Unable to Stop Windows Service Hosting Web API
我将Web api 2作为Windows this.webApp.Dispose();
服务中的自托管服务器运行,在停止期间,我将其称为this.webApp.Dispose();
但是,这似乎不足以优雅地停止服务,因为我收到以下异常:
Failed to stop service. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.HttpListenerException: Failed to listen on prefix 'http://+:8080/' because it conflicts with an existing registration on the machine.
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener, Func`2 appFunc, IList`1 addresses, IDictionary`2 capabilities, Func`2 loggerFactory)
at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app, IDictionary`2 properties)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, Cu...
因此,停止服务的唯一方法是获取该服务的PID,然后使用kill-process。
知道我没有在停止时执行长任务,是否有办法优雅地停止服务?
发现在stop()
Windows服务期间,我实际上是在调用OnStart
事件,该事件将启动Web api而不是停止它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.