launch on startup

J

Jeff Ciaccio

I'm new to vb.net and was wondering what the syntax is for application
events such as starting up or shutting down. For example, if you would just
like to get a user's name with an input box when they open the app or a
form.

Thanks
 
R

Rob Blackmore

It depends on what you want the application to do and what type of
application you are creating (Windows Forms, WPF, Web, etc) - not much help
I know.

Can you give us an idea of the scope of your application and we can offer
more help either on the newsgroup or by emailing me directly.

It is also worth picking up a VB.Net book or two to help you get started.

Kind regards

Rob
 
J

Just_a_fan

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
 
L

Lloyd Sheen

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

Which version of VS are you using. Both 2005 and 2008 have access to all
application events thru the project properties. (not that intuitive but
....). Right click on your project , select properties. On the displayed
dialog select "View Application Events". From the IDE you should be able to
dropdown the events and get the IDE to generate the stubs.

On the same dialog is the "Make single instance application" check box.
This is only available if you have "Enable application framework" checked.

Hope this helps
LS
 
J

Just_a_fan

Which version of VS are you using. Both 2005 and 2008 have access to all
application events thru the project properties. (not that intuitive but
...). Right click on your project , select properties. On the displayed
dialog select "View Application Events". From the IDE you should be able to
dropdown the events and get the IDE to generate the stubs.

On the same dialog is the "Make single instance application" check box.
This is only available if you have "Enable application framework" checked.

Hope this helps
LS

VS2008/VB9 is my current weapon against paying for all software.

And speaking of non-intuitive. You have to check something to get
"Configuration" to appear (it does not even show, never mind disabled)
in Project Properties>Compile. I found it after some searching. I had
seen it before but it went away and finding it was quite a pain since I
could not see it, I did not know what to search for to get it back.
Goodness, some of the options are in the strangest places! I don't
remember what and were you check to get Configuration and Platform to
appear. It is hidden somewhere. Why the would hide it instead of
disabling it is another little mystery of life.

And, yes, dropping down the event name does create the prototype. I had
never done that. It works!

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top