OWIN Stop Server\Service?

巧了我就是萌 提交于 2019-12-23 09:32:23

问题


Using a c# winforms app to start owin

Created a Startup config file

[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();


        }
    }

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)));

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

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

            }


        }

回答1:


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();
}


来源:https://stackoverflow.com/questions/31562192/owin-stop-server-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!