OWIN停止服务器\服务? [英] OWIN Stop Server\Service?

查看:334
本文介绍了OWIN停止服务器\服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用c#winforms应用启动owin

Using a c# winforms app to start 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();


        }
    }

然后在我的Windows窗体上:

And then on my windows form:

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

我该如何停止\重新启动OWIN服务,这将是一个很好的例子吗?

How do I go about stopping\restarting the OWIN service, example would be great?

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

            }


        }

推荐答案

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

WebApp.Start() should return a IDisposable object that you can hold onto, and later dispose of when you want to Stop the server. You'll want to do proper safety checks/exception handling, but a simple example is:

private IDisposable myServer;

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

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

这篇关于OWIN停止服务器\服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆