Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWIN Stop Server\Service?

Tags:

c#

owin

signalr

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

            }


        }
like image 386
D-W Avatar asked Jul 22 '15 11:07

D-W


1 Answers

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();
}
like image 90
Zephyr Avatar answered Sep 17 '22 23:09

Zephyr