By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Help with starting my Windows Forms application properly :-)

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Assuming you want to use your existing design: If you put the
Application.Run in the UIManager constructor, it will block the constructor
causing the app to hang (as you see). Try adding a StartUI method to the
UIManager class that wraps this call instead. Then you could have the
ApplicationManager call the method after constructing the UIManager. All of
this assumes you want to use your existing classes.

"Simon Harvey" <sh856531@microsofts_free_email_service.com> wrote in message
news:eM**************@TK2MSFTNGP09.phx.gbl...
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

Nov 15 '05 #2

P: n/a
Thanks for that.

I've just been sitting and thinking about this problem and I think I
understand the situation better now.

Am I right in thinking that essentially what I need to do is do all my
initialisation of non-ui stuff, before I do Application.Run()?

Before, I didnt understand why Application.Run() should block until the main
form was closed, as this would stop any code after Application.Run() from
being executed. I didnt understand why it worked like that and why that
should be allowed.

Now I am sort of imagining a situation in which I can do all sorts of
initialisation and whatever else I need to do as long as it's done before
Application.Run(). I am sort of imagining Application.Run() as a method that
puts the application into "UI Mode" at which point the application no longer
runs code in a predetermined sequence, but in an event driven manner.

Everything you want to do before the UI shows up, should be done before
switching into this "mode".

I'm sure my understanding is a bit rough, but could anyone tell me if what I
have said even makes the slightest bit of sense?!!

:-)

Thanks all

Simon
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.