I’m trying to seamlessly switch between two independent HttpListener instances on the same address. Currently, there are a few seconds of downtime (where the user would get a 404) after stopping instance 1 and starting instance 2 (and obviously, if instance 2 is started before instance 1 has closed, I get the classic “already registered with http.sys” error).
Any ideas on how to seamlessly switch (without downtime) on the same address?
The classic answer here is an external load-balancer, such as HAProxy, that spreads the load between multiple machines, processes, ports, hosts, whatever. For example, even on a single machine you could have two instances on different ports (unrelated to what the client thinks they are contacting), and switch load to them via HAProxy. This handles all the port / host remapping automatically.
If you want a single process (such as a service), then a trick here is to use AppDomain:
A little messy (you need to worry about creating temporary locations for each version of the app to execute from, etc), but can be very effective.