I have an application written in Silverlight that is used on both Mac and Windows platforms. As part of its functionality, it must only be allowed to run one. We have implemented this using the LocalMessageReceiver approach and it works as expected.
However, we have an issue on the Mac. If the application crashes or is Force Quit, it is impossible to restart the application as the single instance code reports that the application is already running. The only recourse we have found so far is to restart the computer. However, this is inconvenient at best.
Is there a way on Mac OS X to clear the resources used by the LocalMessageReceiver without having to restart the computer? I assume that there are shared resources somewhere in the system, but I haven't found any documentation discussing what those resources are or how to reset them.
Well... as no one else replied... this is my workaround; I cannot explicitly set the code, but I can get you the idea:
If you cannot listen on the LocalMessageReceiver() it can be for two reason
the trick to differentiate the reasons is to try to communicate to the LocalMessageReceiver. Set up a LocalmessageSender, add one handle to the response and try to send a message.
The "real" other silverlight instance would reply. The crash leftover no. So you can wait for a reasonable timeout for a reply.
If there is none (so it's the crash) you have some strategy: for example you can set up a new LocalMessageReceiver (with a "fallback" name) to check for other instances or something like that.
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