.Net multiple app instances but single document
My WPF app can open and edit single documents. I am looking for a tidy approach to allow multiple instances of my WPF app to run but to only allow a given document to be open in one instance of the app. If a user trie开发者_运维知识库s to open a document which is already opened in another instance, I need to pop up a dialog to tell them and allow them to switch to the other app instance if required.
Thanks Dan
One approach is to attempt to take an exclusive lock on the file when you open it. When your other application instance attempts to open the file, an IOException will be raised. You can catch this exception and show a dialog to your user stating that the file is already opened in another application. This scenario should be covered anyway, as the file could be open in a different application that is not yours.
精彩评论