How would you open a file (that has a known file/app association in the registry) into a ‘running instance’ of the application it’s supposed to open in? An example would be, I have Excel open and I click on an XLS file…..the file opens up in the current Excel instance. I want to do this for a custom application…how does the eventing/messaging work that ‘tells’ the current instance that it needs to open a file? Is there a ‘file watcher’ that looks for a request to do so etc? Thanks..
Share
What you want to do is inherit a class from WindowsFormsApplicationBase, setting the protected IsSingleInstance property to true:
The Main method of your app then looks like this:
Note the section marked <1>. You set this up with an event handler for the StartupNextInstanceEvent. This event is fired when the next instance of your app is fired when you have a single instance application (which you specified in the constructor of MyWindowsApplicationBase). The event handler will pass an EventArgs-derived class which will have the command line arguments which you can then process in the running instance of your app.
Then, all you have to do is set the file associations normally for the file types you want your app to process, and you are set.