Ok... very dumb question. static void Main()

  • Thread starter Thread starter Jay B. Harlow [MVP - Outlook]
  • Start date Start date
J

Jay B. Harlow [MVP - Outlook]

MC D,
The Application.Run is a 'message pump', it does not return until
Application.Exit is called. When you pass a form to this method, an event
handler is added to the Form.Closed event, this handler calls
Application.Exit.

For your forms to display and function correctly, you need to call
Application.Run. To exit your app correctly you will need to call
Application.Exit (remember to call Application.Exit!).

To get your Main to work, put Application.Run after you show your two forms.
[STAThread]
static void Main()
{
frmSplash splashForm = new frmSplash();
splashForm.Show();
splashForm.lblStatus.Text = "Loading Preferences...";
//loadPrefs();
hndMainForm = new mainForm();
hndMainForm.Show();
Application.Run();
}

Now! what am I forgetting ;-)

Hope this helps
Jay

MC D said:
I am trying to move my Main() procedure out of a startup form and into it's
own class. I've updated the app settings to use the "Globals" class (which
contains the main form). Here's what I have:

[STAThread]
static void Main()
{
Application.Run();
frmSplash splashForm = new frmSplash();
splashForm.Show();
splashForm.lblStatus.Text = "Loading Preferences...";
//loadPrefs();
hndMainForm = new mainForm();
hndMainForm.Show();
}

This results in nothing happening (no forms are shown). If I remove
Application.Run(); the two forms briefly flash and the app closes. There
must be something I don't understand about what Application.Run does? I
don't want to pass it a form to create beacuse that's what I'm trying to
prevent in the first place.

Thanks for any help.

-D
 
I am trying to move my Main() procedure out of a startup form and into it's
own class. I've updated the app settings to use the "Globals" class (which
contains the main form). Here's what I have:

[STAThread]
static void Main()
{
Application.Run();
frmSplash splashForm = new frmSplash();
splashForm.Show();
splashForm.lblStatus.Text = "Loading Preferences...";
//loadPrefs();
hndMainForm = new mainForm();
hndMainForm.Show();
}

This results in nothing happening (no forms are shown). If I remove
Application.Run(); the two forms briefly flash and the app closes. There
must be something I don't understand about what Application.Run does? I
don't want to pass it a form to create beacuse that's what I'm trying to
prevent in the first place.

Thanks for any help.

-D
 
Ah! That makes sense now. Thanks Jay!

-D
Jay B. Harlow said:
MC D,
The Application.Run is a 'message pump', it does not return until
Application.Exit is called. When you pass a form to this method, an event
handler is added to the Form.Closed event, this handler calls
Application.Exit.

For your forms to display and function correctly, you need to call
Application.Run. To exit your app correctly you will need to call
Application.Exit (remember to call Application.Exit!).

To get your Main to work, put Application.Run after you show your two forms.
[STAThread]
static void Main()
{
frmSplash splashForm = new frmSplash();
splashForm.Show();
splashForm.lblStatus.Text = "Loading Preferences...";
//loadPrefs();
hndMainForm = new mainForm();
hndMainForm.Show();
Application.Run();
}

Now! what am I forgetting ;-)

Hope this helps
Jay

MC D said:
I am trying to move my Main() procedure out of a startup form and into it's
own class. I've updated the app settings to use the "Globals" class (which
contains the main form). Here's what I have:

[STAThread]
static void Main()
{
Application.Run();
frmSplash splashForm = new frmSplash();
splashForm.Show();
splashForm.lblStatus.Text = "Loading Preferences...";
//loadPrefs();
hndMainForm = new mainForm();
hndMainForm.Show();
}

This results in nothing happening (no forms are shown). If I remove
Application.Run(); the two forms briefly flash and the app closes. There
must be something I don't understand about what Application.Run does? I
don't want to pass it a form to create beacuse that's what I'm trying to
prevent in the first place.

Thanks for any help.

-D
 
Back
Top