Search code examples
c#asp.netasp.net-mvcsignalrsignalr-hub

SignalR How to Stop and Start the "Server"


I apologize if this has been answered before or for being a stupid question.

I have a web app (.NET MVC c#) that does a number of different functions. I want to add a new function which could utilize websockets

I have looked at SignalR and it looks fine for my use scenario in terms of while it is active, however I don't want it to be active all the time.

It will only be active for a period of time, where an Admin will "allow the function".

Imagine a Business web app which also has a chat option, but the chat option is only allowed during lunch break.

I don't want SignalR running in the background for the 90% of the time it wont be used, so how do I stop it or create a new instance of the Hub?

** EDIT **

Following the answer below (for which I am grateful), I don't think I made the question clear.

I am not sure how the hub "server" is started and stopped. With the abstraction in Visual Studio (ie just add a SignalR class), I cant work out how to dispose of the Hub and then restart it (create an instance of it)


Solution

  • You would stop the hub "server" in the same way that you would stop a webAPI server, a WCF server, or any web app running on a web-server; Disable it on the server.

    With the abstraction of Visual Studio, it is still running under IIS Express - If you stop your signalR hub "server" from running, when you point your browser to it localhost:12345/signalr/hubs, the page will say something along the lines of "This site can’t be reached".

    But why would you want to stop the hub "server" ? Best to let it run... and impose your lunchtime restriction server side.