OWIN停止服务器\服务?

使用ac#winforms app启动owin

创建了一个启动配置文件

[assembly: OwinStartup(typeof(Chatter.Host.Startup))] namespace Chatter.Host { public class Startup { public void Configuration(IAppBuilder app) { // Any connection or hub wire up and configuration should go here app.MapSignalR(); } } 

然后在我的窗体上:

  private void StartServer() { try { SignalR = WebApp.Start(URL); } catch (TargetInvocationException) { //Todo } this.Invoke((Action) (() => richTextBox1.AppendText("Server running on " + URL))); 

我如何停止\重新启动OWIN服务,例如会很棒?

 private void StopServer() { try { //STOP!! } catch (TargetInvocationException) { } } 

WebApp.Start()应该返回一个可以保留的IDisposable对象,并在以后要停止服务器时进行处置。 您需要进行适当的安全检查/exception处理,但一个简单的例子是:

 private IDisposable myServer; public void Start() { myServer = WebApp.Start(URL); } public void Stop() { myServer.Dispose(); }