Occurs when attempting to start a single-instance application and the application is already active.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
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 DoEvents method.
The StartupNextInstance event is raised only in single-instance applications. To enable single-instance behavior for your application, you must check the Make single instance application check box in the Project Designer.
To make an application single instance
You must use the CommandLine property of the e parameter to access the arguments for subsequent attempts to start a single-instance application. The CommandLineArgs property provides the arguments used to start the first instance of a single-instance application.
The code for theevent handler is stored in the ApplicationEvents.vb file, which is hidden by default.
To access the Code Editor window for application events
The following table lists examples of tasks involving the My.Application.StartupNextInstance event.
Check the command-line arguments of the first application instance
Windows Forms Application
Windows Forms Control Library
Web Control Library
This example uses the e parameter of the /input=, the rest of that argument is displayed.event handler to examine the application's command-line arguments. If an argument is found that starts with
Private Sub MyApplication_StartupNextInstance( ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs ) Handles Me.StartupNextInstance Dim inputArgument As String = "/input=" Dim inputName As String = "" For Each s As String In e.CommandLine If s.ToLower.StartsWith(inputArgument) Then inputName = s.Remove(0, inputArgument.Length) End If Next If inputName = "" Then MsgBox("No input name") Else MsgBox("Input name: " & inputName) End If End Sub
You must enter the code in the Code Editor window for application events. To access this window, follow the instructions from this topic's Remarks section. For more information, see Application Page, Project Designer (Visual Basic).
Available since 2.0