I'm developing a mobile application in .Net Compact Framework. I managed to edit the registry HKEY_CLASSES_ROOT so that a click on a file with the .xyz extension will open my application. Basically, I need to do some operation on this file when it's clicked.
However, I realise that if I do that the first time, it reaches program.cs at static void Main
. But when the program is running and I click on the file with .xyz extension again, it doesn't load the program static void Main
. I tried setting breakpoints at the form that is currently running but still nothing.
So where does it go to? How can I detect file .xyz is clicked and do something?
The big problem you're having is that once the application is running Main will never get called again, and in fact it shouldn't.
Under Windows Mobile, unfortunately, the CF itself attempts to keep applications singletons, so when you try to runt he app a second time, the CLR itself intercepts that and instead brings the existing instance to the fore. One of the unfortunate side effects of this is that you get no opportunity to handle command-line parameters.
To get this to work, you have to do a few things:
You say that you need to perform some operation on a file every time it's clicked. I'm assuming this is something GUI-related, like you want to show properties of the file when it's double-clicked.
Assuming your program has one main form, you could set its MinimizeBox
property to false
and in its Deactivate
event put this.Close();
. This way, when you click a file of the right type, your application will start and read the command line args and display the file details. If the user then closes your app with the OK button in the upper right, it will close out for real so that the next time it opens it will open a new instance and read the command line args properly. Or, if the user just navigates to some other program in WinMo, your application's Deactivate
event will fire, closing the app. Either way, the app is always either open and on top, or completely closed, so clicking a file in file explorer will always open a new instance.
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