[英]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.