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

  • Thread starter Jay B. Harlow [MVP - Outlook]
  • 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
 
M

MC 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
 
M

MC 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
 

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