473,614 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.Run vs myForm.ShowDial og

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.ShowDial og();

and run the application with no problem.

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

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 10193
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*****@ualber ta.ca> wrote in message
news:em******** ******@TK2MSFTN GP11.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.ShowDial og();

and run the application with no problem.

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

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*****@ualber ta.ca>
| Subject: Application.Run vs myForm.ShowDial og
| 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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: kzin.phys.ualbe rta.ca 129.128.162.60
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1922 26
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.ShowDial og();
|
| and run the application with no problem.
|
| Is there any reason why I should use Application.Run instead of
| myForm.ShowDial og?
|
| 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
1302
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 scraping that approach and doing : Myform mForm = new MyForm();
20
6471
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 the mutex is in a local variable in Main(), and my program launches any windows before Application.Run(), it will lose the mutex upon doing so. It shouldn't, as far as I can see. Moving the mutex variable outside Main() and making it static...
4
5843
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 vb.net that doesnt seem to do alot most of the time so far as i can tell. So im using form.showdialog all the time. But it seems as though once i call this code, all control transfers to the open form and only when closed the control returns to the...
4
10455
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 Form like "batch-processing", starting :DoSomething() in my code:
5
2365
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 browse form. The user would access the Add Form by clicking on the Add Employee Button. Unfortunatly when you use MyForm.ShowDialog(this), the entire application is locked out, which is the default and accepted behaviour of Windows Forms.
8
3327
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. Closing the form is not enough because there is a lot of forms open TIA Rodrigo Juarez
3
1583
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. 1. I already have a classlibray project but I don't think I can include a "form" in it, right? 2. So, do I make this form into a dll so other application can include it as a reference? 3. To do the item 2, does that mean that I would create...
10
1886
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 use this way: MyMainForm myForm = new MyMainForm(); myForm.ShowDialog();
3
6619
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 Form I call another child form. From that child form I need to call myModalForm. I have tried:
0
8198
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8294
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8444
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7115
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.