Problem with Application.Run

  • Thread starter Thread starter Simon Harvey
  • Start date Start date
S

Simon Harvey

Hi all,

I am trying to get my win forms application to start, but I'm hitting a
problem which I am certain is really simple.
The start for my application is ApplicationManager.cs. This class contains
the Main() method and a very simple constructor. The class looks something
like this:

public class{

[STAThread]
static void Main(){
ApplicationManager theApp = new ApplicationManager()
}

public ApplicationManager(){
...
}
}

The ApplicationManager class is hopefully going to be the central area to my
application. It is going to link the UI layer to the data layer. It's
basically going to be a class that coordinates everything.

At startup, one of the ApplicationManager's jobs is to start the user
interface. I've made another class called UIManager that the
ApplicationManager should interact with to do this.
The UIManager should be the only class that has direct access to the forms
defined in the application.

This is my problem (thanks for bearing with me!):

I don't know where to put the Application.Run() line. I want the UIManager
to create the main form of the user interface, however, if I put
Application.Run in the contructor of the UIManager - the application hangs:

private MainForm mf;

public UIManager (){
mf = new MainForm();
Application.Run(mf);

// Nothing will run beyond this point!
}

I know I have to use Application.Run method to get the Windows Message pump
'thingy' to work - but how can I start the message pump the way I want to,
without the application hanging?

Thanks thanks and more thanks to anyone who can help. This problem has been
bugging me on and off for ages now.

Simon
 
Simon

I have done similar tasks as follows (VB.Net):

Dim myForm as new frmMainForm

myForm.Acivate ()
myForm.methodsForInitialization(etc)
myForm.ShowDialog() 'For modal display of UI
myForm.Show() 'For modeless display of UI

Hope this gives you some ideas.

Gary
 
Try placing your Application.Run(new <YourForm>) in Main Method. You don't
have to declare and instantiate your form because the new keyword is
included in the Application.Run() method.

Hope this helps! :)

Ann
 
Back
Top