c# - OWIN 停止服务器\服务?

标签 c# signalr owin

使用 c# winforms 应用启动 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 对象,并在您想要停止服务器时处理。您需要进行适当的安全检查/异常处理,但一个简单的示例是:

private IDisposable myServer;

public void Start() {
    myServer = WebApp.Start(URL);
}

public void Stop() {
    myServer.Dispose();
}

关于c# - OWIN 停止服务器\服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31562192/

相关文章:

c# - 哈希值是否全局唯一

c# - 文件上传导致模型验证失败

signalr - Blazor Server 每次使用的连接数受浏览器限制

asp.net-web-api - 随着 SerilogWeb.Owin 停止,是否有 "official"集成?

asp.net-core - 在.Net core中共享默认的OWIN token

c# - 结构图 - 在运行时用模拟对象替换接口(interface)

c# - 如何检索已编译方法的源文件?

c# - 如何将 Ninject 和 MVC 与单个接口(interface)的多个实现一起使用?

c# - 如何创建基于 HTTP header 的自定义身份验证机制?

c# - 通知 SignalR 客户端 IIS 重启/关闭