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)
{
}
}
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With