Starting a project with 'Sub Main'
-
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)
-
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)
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
-
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
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)
-
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)
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
-
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
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)