Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Starting a project with 'Sub Main'

Starting a project with 'Sub Main'

Scheduled Pinned Locked Moved Visual Basic
questionhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fade Amit BS
    wrote on last edited by
    #1

    I am having a problem while setting the startup object to sub-main, even though inside the sub main i have loaded two forms that have their own things to do, to programs ends at the end of sub main, so how do i keep it alive? - Note: using a modal form (myForm.ShowDialog) is not an option as my project needs to switch focus between forms. Fade (Amit BS)

    D 1 Reply Last reply
    0
    • F Fade Amit BS

      I am having a problem while setting the startup object to sub-main, even though inside the sub main i have loaded two forms that have their own things to do, to programs ends at the end of sub main, so how do i keep it alive? - Note: using a modal form (myForm.ShowDialog) is not an option as my project needs to switch focus between forms. Fade (Amit BS)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Loading and showing two forms will not keep your app open. Since your sub Main ends, so does your app. Really, what you should be doing is starting your app with a Form, since the message pump in this form will not end, and therefore your app, until the pump recieves a WM_QUIT message. What is the purpose of having a Sub Main in your app? RageInTheMachine9532

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Loading and showing two forms will not keep your app open. Since your sub Main ends, so does your app. Really, what you should be doing is starting your app with a Form, since the message pump in this form will not end, and therefore your app, until the pump recieves a WM_QUIT message. What is the purpose of having a Sub Main in your app? RageInTheMachine9532

        F Offline
        F Offline
        Fade Amit BS
        wrote on last edited by
        #3

        Well, i know that using a form as a startup object will keep it alive, the main reason to use a 'Sub Main' is to get command line arguments, and i find it more organized to create an instance of the main form through code. So a. commandline arguments and b. neet code. any suggestions? Fade (Amit BS)

        D 1 Reply Last reply
        0
        • F Fade Amit BS

          Well, i know that using a form as a startup object will keep it alive, the main reason to use a 'Sub Main' is to get command line arguments, and i find it more organized to create an instance of the main form through code. So a. commandline arguments and b. neet code. any suggestions? Fade (Amit BS)

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Fade (Amit BS) wrote: a. commandline attributes You don't need a Sub Main for command line arguments. In you Form_Load event, or something else close to your app starting up, just use Environment.GetCommandLineArgs() to get a String array of the arguments. Fade (Amit BS) wrote: b. neet code But a pain in the butt to keep an app running. It's MUCH easier to just have a main form and have that form launch the others than it is to keep a Sub Main in a relatively infinite loop watching for and waiting for all the open forms, most of which it has no clue even exist, to be closed and unloaded. Think about it. Pick any app in Windows, like Word, VS.NET... They all have a main form and a bunch of helper forms that the main form launches and manages. RageInTheMachine9532

          F 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Fade (Amit BS) wrote: a. commandline attributes You don't need a Sub Main for command line arguments. In you Form_Load event, or something else close to your app starting up, just use Environment.GetCommandLineArgs() to get a String array of the arguments. Fade (Amit BS) wrote: b. neet code But a pain in the butt to keep an app running. It's MUCH easier to just have a main form and have that form launch the others than it is to keep a Sub Main in a relatively infinite loop watching for and waiting for all the open forms, most of which it has no clue even exist, to be closed and unloaded. Think about it. Pick any app in Windows, like Word, VS.NET... They all have a main form and a bunch of helper forms that the main form launches and manages. RageInTheMachine9532

            F Offline
            F Offline
            Fade Amit BS
            wrote on last edited by
            #5

            ok, You win :) the command line arguments solution has tilted it to your favour, especially when there is no easy 'right' way to keep the app running via sub main. thanx, i'll go back to using a main form. Fade (Amit BS)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups