473,320 Members | 1,799 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,320 software developers and data experts.

Application.Run vs myForm.ShowDialog

When you crate a Windows application the wizard adds a line like:

Application.Run( new MyMainForm() );

Out of curiosity I replaced this with:

MyMainForm myForm = new MyMainForm();
myForm.ShowDialog();

and run the application with no problem.

Is there any reason why I should use Application.Run instead of
myForm.ShowDialog?

The reason I ask, is I want to place lots of smarts before launching the
GUI. Using agile programming techniques (unit testing, refactoring) I want
to create a functional application before adding the GUI layer. The reason
for doing it this way is that I end up with testable, reusable code, and no
business login in the GUI. Since the GUI is an add-on, the same application
code can be deployed, in a windows app, a service, a web service, a web
form, or console app.

By the way, I added a parameter to the MyMainForm constructor to so that the
GUI code can call back into the objects which get created before the form is
created.

Bill
Nov 15 '05 #1
2 10169
When you call show dialog, the run-time will load the application if it is
not running in order to honor the request. If it is running, the request can
be honored immediately otherwise, application run is called. This incurs a
runtime overhead check.

There is no overhead check for the application run event. (well not really,
depending on whether multiple applications can exist, but for the most part
this is true).

"Bill Burris" <wb*****@ualberta.ca> wrote in message
news:em**************@TK2MSFTNGP11.phx.gbl...
When you crate a Windows application the wizard adds a line like:

Application.Run( new MyMainForm() );

Out of curiosity I replaced this with:

MyMainForm myForm = new MyMainForm();
myForm.ShowDialog();

and run the application with no problem.

Is there any reason why I should use Application.Run instead of
myForm.ShowDialog?

The reason I ask, is I want to place lots of smarts before launching the
GUI. Using agile programming techniques (unit testing, refactoring) I want to create a functional application before adding the GUI layer. The reason for doing it this way is that I end up with testable, reusable code, and no business login in the GUI. Since the GUI is an add-on, the same application code can be deployed, in a windows app, a service, a web service, a web
form, or console app.

By the way, I added a parameter to the MyMainForm constructor to so that the GUI code can call back into the objects which get created before the form is created.

Bill

Nov 15 '05 #2

Hi Bill,

I think the behavior is almost the same with Application.Run and
Form.ShowDialog.
But Application.Run adds an event handler to the mainForm parameter for the
Closed event. The event handler calls ExitThread to clean up the
application.
When Form.ShowDialog is called, the code following it is not executed until
after the dialog box is closed, so you should not place initialize
operation below the ShowDialog method.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Bill Burris" <wb*****@ualberta.ca>
| Subject: Application.Run vs myForm.ShowDialog
| Date: Fri, 17 Oct 2003 16:10:34 -0600
| Lines: 29
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <em**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: kzin.phys.ualberta.ca 129.128.162.60
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:192226
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| When you crate a Windows application the wizard adds a line like:
|
| Application.Run( new MyMainForm() );
|
| Out of curiosity I replaced this with:
|
| MyMainForm myForm = new MyMainForm();
| myForm.ShowDialog();
|
| and run the application with no problem.
|
| Is there any reason why I should use Application.Run instead of
| myForm.ShowDialog?
|
| The reason I ask, is I want to place lots of smarts before launching the
| GUI. Using agile programming techniques (unit testing, refactoring) I
want
| to create a functional application before adding the GUI layer. The
reason
| for doing it this way is that I end up with testable, reusable code, and
no
| business login in the GUI. Since the GUI is an add-on, the same
application
| code can be deployed, in a windows app, a service, a web service, a web
| form, or console app.
|
| By the way, I added a parameter to the MyMainForm constructor to so that
the
| GUI code can call back into the objects which get created before the form
is
| created.
|
| Bill
|
|
|

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Simon Harvey | last post by:
Hi everyone, Can anyone tell me if there is any compelling reason not to start my application in a way other than : Application.Run(new MyForm()); I'm not too sure of the implications of...
20
by: Michael A. Covington | last post by:
See: http://www.ai.uga.edu/mc/SingleInstance.html While attempting to use a mutex to allow only one instance of my app to run at a time (Recipe 4.12 in C# Programmer's Cookbook), I found that if...
4
by: Jm | last post by:
Hi all Im not sure of the best way to be displaying my forms and just want a bit of clarification. Being only recently moved to vb.net im still used to the old vb6 form.show method, now under...
4
by: Peter | last post by:
Hi I have a Windows Form (myForm()) doing somethig. myForm() should be modal. Normaly the action initated by user - pressing a Button, callling myForm:DoSomething() Now i will use the same...
5
by: scott blood | last post by:
Hello, We currently have an application that has a lot of screens that allow users to add new data to the system. These forms are currently accessed via a browse form, such as the employee's...
8
by: Rodrigo Juarez | last post by:
Hi I'm using Visual Studio 2005 with visual basic, developing winforms applications I'm adding try catch blocks for error handling and I want to close the application when I got an error....
3
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2.0, Win2k server for a Windows applcaiton. I have a main application where there is a a form and the codes that I would like to make it reuseable by other applications....
10
by: wael20 | last post by:
Hello, C# !!! How can i back from Application.Run to place where was is called? or, what should i do, when i must to use Application.Run( new MyMainForm() ) to run my application? so i can´t...
3
by: elmbrook | last post by:
I am unable to open a child form as a modal form. Here is my scenario I have a MainForm which is a toplevel form. Inside the MainForm I have a Toolbar Form which is a child. From the Toolbar...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.