OWIN Stop server \ Service?

Using c # winforms application to run owin

Created a launch configuration 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 in my window form:

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

How do I stop stopping / restarting the OWIN service, for example, would be great?

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

            }


        }
+4
source share
1 answer

WebApp.Start () should return an IDisposable that you can hold and delete later when you want to stop the server. You will need the correct security checks / exception handling, but a simple example:

private IDisposable myServer;

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

public void Stop() {
    myServer.Dispose();
}
+7
source

Source: https://habr.com/ru/post/1599082/


All Articles