Home > Enterprise >  Show hidden application on trying to launch a new instance of a single instance application
Show hidden application on trying to launch a new instance of a single instance application

Time:04-26

I'm working on a single instance application in VB.NET that goes hidden when we minimize the form:

Private Sub Form_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        Me.Visible = False
    End if
End Sub

Then, if I try to launch it again, it doesn't open because it is already running (so far, so good).
Is it possible to make it just visible on this stage? I mean, can I just make the application visible if I try to launch it when it's already running?
I suppose this can be done because there are some applications with this exact behavior.

CodePudding user response:

In your WinForms project properties select "View Application Events" (My Project -> Application -> View Application Events). From there you can see the events that get fired at the start and end of your application. One of which is the StartupNextInstance event handler. In here you should be able to make your form visible again.

Per docs:

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 Startup.

StartupNextInstance Documentation

  • Related