Problems sharing audio & MIDI devices with other applications

On macOS this has never been a problem, but on Windows, sharing audio and MIDI devices among multiple host applications is a challenge. Some host will sooner or later claim access to a device and take it away from you. When your host is put back into the foreground, it will most likely be silent and deaf. Some hardware drivers seem to be more forgiving than others, but it’s completely unpredictable.

How do you deal with this? Is there a way to get notified when a device is taken away? Is there a way to (forcefully) reclaim a device?

I may be completely on the wrong path, so if you never experienced this issue, learning about that would also be helpful.