I just found "ApplicationEvents.vb" which is hidden by default. I
forget how to show it but it is probably easy to find -- I found it so
how hard could it be!
It has several events but no prototypes. That seems a tremendous
oversight!
I am using the one for StartupNextInstance to notify the user that the
program was started twice. The application takes care of exiting (if
you set the single instance check in My Project>Application) but not
notifying the user. If the application is hidden in some way and the
user clicks on the icon/shortcut once again, then just quitting is not
helpful to the user. They will probably click it a few more times and
then logoff or reboot thinking something is drastically wrong. So a
message seems appropriate.
It took a little time to get it right since there are no prototypes.
Here are the events that this namespace handles:
------------------------------------------------
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form
is created.
' Shutdown: Raised after all application forms are closed. This event
is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an
unhandled exception.
' StartupNextInstance: Raised when launching a single-instance
application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is
connected or disconnected.
------------------------------------------------
That might be too early for you if you want to get input from a text
box, though. That's code after you are running, not during startup.
Here is the code for notifying the user of a multiple invocation:
Private Sub NotAgain(ByVal sender As Object, ByVal e As
Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs)
Handles Me.StartupNextInstance
MsgBox("Only one copy of PVM1010 Companion can run on a computer.
Second invocation is exiting.")
End Sub
(note the lines are wrapped due to Usenet length restrictions, not VB
line continuation)
To make this work for startup, remove the characters "NextInstance"
everywhere it appears. I don't know the prototypes for the other calls.
Good luck on that. Intellisense might help you with it but you have to
type it all manually as far as I can tell.
Mike