Gotta love VS.NET

Published 5 September 6 6:6 AM | GregLow

Recently while working with a client on a VB.NET project, we had the need to create an application that would:

1. Automatically open up if not already open

2. Only ever have a single instance open

3. Automatically open a child window based upon a command line parameter.

So, if the program wasn't already open and we said:

C:\> MyApp.exe SomeCustomer

you'd end up with the app opening and the details for that customer shown in a sub-window. However if the app was already open, the same command would just launch sub window.

It ended up quite easy. All that was needed was:

1. Create a module (to put a global reference to the app's startup form)
2. In the form load for the startup form, set the global reference to Me and launch the child form if there was a command line parm.
3. Set the project properties to Single Instance Application.
4. In the application NextInstance event handler, use the global reference to the main form to call a method to launch the child form based on the command line parms.