I suspect you don't process command line.
(for a robust command line utility, you may want to see my work:
Enumeration-based Command Line Utility[
^].)
Please forgive me if this is not an answer: you did not explain your problem in full.
Here is what I suspected and why: you develop drag-and-drop as some control feature, which works when your UI is already shown. You did not explain this exactly, because the Shell also has its drag-and-drop functionality. You put registration of your application in your installation. What's the missing link? Command line, I don't know what else. You never said you processed it.
No events involved, this is simpler than that.
[EDIT]
After OP confirmation, I know the problem is command line.
Consider the application's entry assembly has a main (start-up) module in the file
application.exe
, and the system Registry has the file extension registration records which show system Shell to use this application, with full path name of this file. Let's assume this is an extension "
.myext
". In this case, when a file, for example "
mydata.myext
" is clicked on any file manager using the Shell, it created a process using the following command line:
application.exe mydata.myext
(with full path name оf
application.exe
.)
During run-time, this command line will be passed as a parameter to applications entry point, such as function
main
, it also can be retrieved using the property
System.Environment.CommandLine
. The application should be responsible for finding the file (if a parameter is a file, like in your case) and processing it.
Much more difficult case if the application is already running, and you need to load a file in first instance. This is all about single-instance behavior, which can only be implemented by the application itself. The explanation of the required machinery could be a matter of a while article, may be a big article. Here is the schematic description:
1) Instance of your application #1 is running;
2) You click in your file with registered extension — instance #2 is started;
3) instance #2 detected that instance #1 is running;
4) instance #2 sends it command line data to instance #1;
5) when command line data is transmitted, instance #2 terminate itself;
6) when command line data is transmitted, instance #1 peforms processing of the command line (locate and load the file(s), etc.)
The best way to communicate between instances in .NET is remoting (based on named pipes, because the instances are always on the same computer. The detection of the already running instance is best implemented using the same thing: if instance #1 does not accept connection, it means it is not running.
That's it, a complete answer. If you need more detail, please ask concrete questions, otherwise formulate a separate question on a new page.
Good luck.
—SA