Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
How can I change my program to start from "Sub Main"? I have only found a selection for "Startup Form". I do not always need to show the main form before exit.
Posted (edited)
have you tried putting a Public Shared Sub Main in the form's code?

 

Doesn't it then load all the objects I have used in my main form? I want to be sure nothing unnecessary is loaded. Especially I don't want to load the MediaPlayer dll if it is not needed. Sometimes it is needed and sometimes not.

 

Besides it didn't work. I tried to put this in my main form's class, but the form opens up normally:

 

   Public Shared Sub Main(ByVal CmdArgs() As String)
       End
   End Sub

Edited by JumpyNET
  • Leaders
Posted

Google comes to the rescue!

A Google search for vb.net 2005 "sub main" yields this.

 

Microsoft has introduced the Application Framework which encapsulates many tasks associated with creating an application. One of the function provided by the Application Framework is to start your application up for you on its own terms, which does not include a Sub Main. Visit the link to learn how to work around this issue.

[sIGPIC]e[/sIGPIC]
Posted (edited)

Problem solved!!

 

I found this in AplicationEvents.vb. The Startup seems just what I'm looking for. :D Thanks for your help marble_eater and mskeel!!

 

 

Namespace My

   '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 is terminating 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.

   Class MyApplication

       Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
           MsgBox("Bye bye!")
           End
       End Sub

   End Class

End Namespace

Edited by JumpyNET

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...