2

I have created a custom file type that is recognized by my application, and I would like to know what event is triggered when I open my application by double-clicking a file of this type. I have placed breakpoints at the beginning of handlers for Form.Shown and Form.Load, as well as at the beginning of the form's constructor, but the application never hits the breakpoints.

tshepang
  • 12,111
  • 21
  • 91
  • 136
user667118
  • 67
  • 10

3 Answers3

2

For using that file : Just get your file from commandline args and process it on which event you want. My.Application.CommandLineArgs

After this if you want to debug: You can put that arguments inside Properties-Debug- Start Options -Commandline arguments (argument will be your file) and put breakpoint on the event where you were processing that file

Happy debuggings

qwr
  • 3,660
  • 17
  • 29
  • Thank you! I knew about CommandLineArgs, and that's what I wanted to test out, but I couldn't do this from the debugger because of what Adrian mentioned. – user667118 May 10 '13 at 06:34
2

If you're opening the application by double-clicking on the file in your computer's filesystem the debugger built in to Visual Studio won't be attached to the application's process and so won't break at your breakpoints. You can attach the debugger to a running process, but what you're talking about happens fairly quickly, so you will almost certainly not be able to attach to the process fast enough to set your breakpoints and catch the execution as it passes them.

Ultimately, the events triggered when you open your application via a file association is no different to opening the application by running its executable file.

Adrian
  • 2,825
  • 1
  • 22
  • 32
  • Thanks! I just realized that this was my problem. It sounds difficult to debug a running process, so I'll just try it out after building the application. I can verify the results by examining some temp files. – user667118 May 10 '13 at 06:32
  • 2
    @user667118 - you might find [How To: Launch the Debugger Automatically](http://msdn.microsoft.com/en-us/library/a329t4ed(v=vs.100).aspx) a useful article if you're diagnosing startup issues. – Damien_The_Unbeliever May 10 '13 at 07:08
0

If you're creating your program as a Single Instance Application, then you'll receive the Startup event for your first instance, and the StartupNextInstance event for each subsequent invocation.

Each of these events hangs off of My.Application and provides the command line parameters that were passed to each invocation.

If you're not using a Single Instance Application, the Startup event is still available.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448