What is StartupNextInstance event?

Herry Markowitz

Well-known member
Joined
Oct 22, 2015
Messages
46
Programming Experience
1-3
Hi experts,
I have got following code from here VB.NET: Single Instance Application-VBForums.

VB.NET:
Namespace My
   Partial Friend Class MyApplication
       Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, _
ByVal e As _
Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
           e.BringToForeground = True
       End Sub
   End Class
End Namespace

What is that code doing?
 
Last edited:
Firstly, you've made that code almost impossible to read. When posting code snippets, please use plain text inside xcode tags, i.e.

[xcode=vb]your code here[/xcode]

The tag will take care of syntax highlighting so you won't end up with loads of colouring tags to obfuscate the code.

Anyway, the VB.NET application framework, which is enabled by default when you create a VB.NET application project, handles a number of application management tasks for you. The Startup event is raised when the application starts up and is its handler is where you would put code that would normally go in the Main method of an application without the framework enabled.

When you make your application single-instance, when you run it the first time it will raise its Startup event as normal. If you run it again while that first instance is still running, instead of a new instance starting and raising its Startup event, the original instance will raise its StartupNextInstance event. This gives your application the chance to react to the user request. One of the most common tasks in the StartupNextInstance event handler is to open a new document in the existing application. In your code, the existing application is being given focus.
 
Back
Top