A single-instance application raises the StartupNextInstance event when you attempt to restart the application when it is already active. When a single-instance application starts for the first time, it raises the Startup event. For more information, see My.Application.Startup Event and How to: Specify Instancing Behavior for an Application (Visual Basic).
This event is part of the Visual Basic Application model. For more information, see Overview of the Visual Basic Application Model.
This event is raised on the application's main thread with the other user-interface events. This allows the event handler to access directly the application's user interface. However, if the application is busy handling another user-interface event when this event is raised, this event cannot be processed until the other event handler finishes or calls the My.Application.DoEvents Method.
You must use the CommandLine property of the e parameter to access the arguments for subsequent attempts to start a single-instance application. The My.Application.CommandLineArgs Property provides the arguments used to start the first instance of a single-instance application.
The code for the StartupNextInstance event handler is stored in the ApplicationEvents.vb file, which is hidden by default.
To access the Code Editor window for application events
With a project selected in Solution Explorer, click Properties on the Project menu.
Click the Application tab.
Click the View Application Events button to open the Code Editor.
For more information, see How to: Handle Application Events (Visual Basic).