473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help with starting my Windows Forms application properly :-)

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
2 1419
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
4
by: Joey Powell | last post by:
Hello all. For a long time now I have been struggling with a .net Windows Forms problem. In several of my applications, I use the "Process" class from System.Diagnostics to accomplish various task...
22
by: Colin McGuire | last post by:
I apologize for posting yet another scrollbar question. Here is my code. All I want is for a diagonal line to appear from coordinates (0,0) to (width,height) in a usercontrol regardless of whether...
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
3
by: trialproduct2004 | last post by:
Hi all i am having error is multi threaded application. I have function in which i am opening form and starting thread. But while doing this i am getting following error. This exception is...
0
by: Marcus Kwok | last post by:
I have written a class (Windows Form) in Managed C++ that accepts an array of image filenames and will display them sequentially. All images will be the same size. I got it to work, but I know...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.