471,603 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

What happens after Application.Run() ?

Code placed after the statement Application.Run() is executed - is there
any reason why this is allowed (I can't see the point of permitting
statements after the "entry point" call) - akin maybe, to allowing
statements after "main" in C/C++

Dec 1 '05 #1
2 2592
Hi Ann,
Code placed after the statement Application.Run() is executed - is there
any reason why this is allowed Application.Run() is just a normal method, like other methods. You can
place any code after it to do anything you wish to. I don't see any
point why it should not be allowed.(I can't see the point of permitting
statements after the "entry point" call) - akin maybe, to allowing
statements after "main" in C/C++

What is "statements after main"? In C#, the Main function is the entry
point, not Application.Run.

Thi

Dec 1 '05 #2
Ann,

Application.Run starts the application message loop. It loops until WM_QUIT
is pulled off of the message queue and then the code in the main method
continues after the loop.

In C or C++ application if you don't use a framework such as MFC your
WinMain method will look something like:

[register windows class]
[create main application window]
[show the window]
while (GetMessage( lpMsg, hWnd, 0, 0))
{
TranslateMessage(lpMsg)
DispatchMessage(lpMsg)
}
[cleanup code]

Ofcourse this is very basic form of the message loop. Real application use
little bit more.

The following is very simplistic approximation of what happen in the C#
windows form application too.

[register windows class]
[create main application window]

is realized by instantiating the main form

[show the window] and the message loop

is inside the Application.Run

and the [cleanup code] is the code after the Application.Run.

As you can see there is no reason this code shouldn't be executed.

I think you get confused of what the C++ frameworks do.

Don't forget that main methods is the entry point of C/C++ program, but the
entry point fo one Windows application is WinMain. The frameworks implement
this WinMain method internaly (inside the framework) inside they do all the
dirty work of registering windows classes, etc then they call one "fake"
*main* method that you declare and after all this they start the message
loop. This might be the reason why your application is not allowed to have
code that executes after the application closes.

I just want to make clear that I made up the scenario for the framework
above and this is not how comersila (e.g. MFC or VCL) frameworks works, but
the idea is that they hide a lot of the details and they dictate how the
code should be constructed.

HTH
Stoitcho Goutsev (100) [C# MVP]

"Ann Huxtable" <an**********@research-labs.de> wrote in message
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Code placed after the statement Application.Run() is executed - is there
any reason why this is allowed (I can't see the point of permitting
statements after the "entry point" call) - akin maybe, to allowing
statements after "main" in C/C++

Dec 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

92 posts views Thread by Reed L. O'Brien | last post: by
121 posts views Thread by typingcat | last post: by
140 posts views Thread by Oliver Brausch | last post: by
51 posts views Thread by jacob navia | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by CCCYYYY | last post: by

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.