StartupNextInstance Event


StartupNextInstance Event

Location

My.Application.StartupNextInstance

Syntax

     Public Sub Me_StartupNextInstance(ByVal sender As Object, _        ByVal e As StartupNextInstanceEventArgs) _        Handles Me.StartupNextInstance     End Sub 


sender (required; Object)

The object that raised the event


e (required; StartupEventArgs)

An event parameter that contains information about the command-line arguments, using the Microsoft.VisualBasic.ApplicationServices.StartupEventArgs class

Description

The StartupNextInstance event occurs in single-instance applications when subsequent instances of the application begin. The initial use of the application fires the Startup event, not the StartupNextInstance event. Non-single-instance applications never call the StartupNextInstance event.

Public Members

The e argument to this event, as an instance of the StartupEventArgs class, includes the following notable public members.

Member

Description

Cancel

Property. Setting this Boolean value to true causes the newly initiated instance of the application to exit without continuing.

CommandLine

Property. A collection of the command-line arguments used to start this specific instance of the application. The application path itself is not one of the collection members; the first member is the first true argument. Do not use the My.Application.CommandLineArgs property, as that only includes the arguments for the initial instance.


Usage at a Glance

  • This event is only available in Windows Forms applications.

  • This event handler can be found in the ApplicationEvents.vb source code file for your project. This file is normally hidden, but it can be viewed by toggling the Show All Files button in the Solution Explorer window in Visual Studio.

  • Applications are multi-instance by default. To set an application as single-instance, alter the project's Application Properties, setting the "Make single instance application" field.

Example

The StartupNextInstance event's code appears in the ApplicationEvents.vb file in a Windows Forms application.

     Namespace My        Class MyApplication           Private Sub MyApplication_StartupNextInstance( _                 ByVal sender As Object, ByVal e As _                 Microsoft.VisualBasic.ApplicationServices. _                 StartupNextInstanceEventArgs) _                 Handles Me.StartupNextInstance              Console.WriteLine("I'm already running!")           End Sub        End Class     End Namespace 

Related Framework Entries

  • Microsoft.VisualBasic.ApplicationServices.StartupEventArgs Class

  • Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.StartupNextInstance Event

See Also

Application Object, CommandLineArgs Property, Shutdown Event, Startup Event, UnhandledException Event




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net