Jeff C
Jeff C

Reputation: 11

StartupNextInstance in VB.net

I am trying to implement StartupNextInstance for a single-instance application, to simply add a messagebox warning that the application is already running when running from code, rather than just switching to the active application w/o notice. Currently when I start the application from code in Visual Studio and I already have the compiled version running, it switches to the compiled version and stops debugging. I want it to be obvious that it has switched to the compiled version rather than just switching w/o any notice.

I have "Make single instance application" checked:

Project Properties:
Project Properties

and have added the following to ApplicationEvents.vb:

        Private Sub MyApplication_StartupNextInstance(sender As Object, e As StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
#If DEBUG Then
      MsgBox("PI is alread running.", Nothing, MsgBoxStyle.Information)
#End If
    End Sub

But the code in the Sub never fires.

What am I missing?

Upvotes: 0

Views: 406

Answers (1)

Jeff C
Jeff C

Reputation: 11

OK, just reread and finally get @Hans Passant's comment. It doesn't fire in the second instance, only the first/existing instance. Doh!

Upvotes: 1

Related Questions