【问题标题】:OWIN Stop Server\Service?OWIN 停止服务器\服务?
【发布时间】:2017-08-11 21:47:57
【问题描述】:

使用 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)
            {

            }


        }

【问题讨论】:

    标签: c# signalr owin


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-05-05
      • 2011-07-07
      • 2020-02-06
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 2023-04-02
      • 2014-11-18
      • 2020-01-23
      相关资源
      最近更新 更多