473,386 Members | 2,050 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,386 software developers and data experts.

Ending a program while in Form_Load

Dom
How do I end a program while in Form_Load? I tried both this.Close(),
and Application.Exit(), but neither will just end the program there
and then. Instead, both allow Form_Load to continue.
Mar 25 '08 #1
4 1907
On Tue, 25 Mar 2008 14:09:52 -0700, Dom <do********@gmail.comwrote:
How do I end a program while in Form_Load? I tried both this.Close(),
and Application.Exit(), but neither will just end the program there
and then. Instead, both allow Form_Load to continue.
Well, I suppose you could just throw an exception, or just put a "return"
statement after your call to Application.Exit(). That would prevent the
rest of your Load event handler from executing.

The Application.Exit() method isn't like the old CRT "exit()" function.
It doesn't terminate the process. It just signals to the application
message pumps to stop and closes all the windows.

I'm not aware of a .NET equivalent to "exit()", though of course an
unhandled exception can terminate the application, albeit messily. You
should avoid implementing code that just terminates the process. It's
extremely unlikely that there's a good reason for wanting to do this, and
you're better off exiting your application cleanly.

Pete
Mar 25 '08 #2
On Tue, 25 Mar 2008 14:59:37 -0700, Jon Skeet [C# MVP] <sk***@pobox.com>
wrote:
>I'm not aware of a .NET equivalent to "exit()" [...]

Environment.Exit() is *reasonably* close to exit() I believe.
Perhaps. The docs are extremely vague on exactly how it operates, but
yes...it appears reasonably close to exit().

Still, I wouldn't recommend it as a correct way of exiting a .NET Forms
application. :)

Pete
Mar 25 '08 #3
On Wed, 26 Mar 2008 14:17:57 -0700, Ignacio Machin ( .NET/ C# MVP )
<ig************@gmail.comwrote:
I agree with you. But maybe his main form is just a splash form, if so
it would make sense to display it
I'm not sure what you mean. The OP has made it very clear that he wants
to optionally continue with the program based on the user's response to a
_dialog_. I don't think there's any "maybe" about this hypothetical
splash form of which you speak.

On the other hand, if one is talking more generally about how to display a
splash form, sure...that's possible and wouldn't involve any conditional
stuff based on the display of that form. But I'm not sure how that'd be
relevant in this thread.

Pete
Mar 26 '08 #4
Dom
On Mar 26, 6:41*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Wed, 26 Mar 2008 14:17:57 -0700, Ignacio Machin ( .NET/ C# MVP ) *

<ignacio.mac...@gmail.comwrote:
I agree with you. But maybe his main form is just a splash form, if so
it would make sense to display it

I'm not sure what you mean. *The OP has made it very clear that he wants*
to optionally continue with the program based on the user's response to a *
_dialog_. *I don't think there's any "maybe" about this hypothetical *
splash form of which you speak.

On the other hand, if one is talking more generally about how to display a*
splash form, sure...that's possible and wouldn't involve any conditional *
stuff based on the display of that form. *But I'm not sure how that'd be*
relevant in this thread.

Pete
Pete got it right. I don't want the main form shown at all if the
user cancels from the dialog that comes before it. The dialog gives
the user the options that are available at the moment, none of which
may be appropriate.

Pete's solution worked fine for me.

Dom
Mar 27 '08 #5

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

Similar topics

1
by: Travis | last post by:
I have encountered a problem with ending any program I build with VB.net and was hopeing someone might have an answer. This is a simple example of the code that will cause an error: In a...
1
by: Ricky | last post by:
I'm trying to run a program directly from the web. It's working perfectly, but a simple "End" statement or "Application.Exit" do not work for me and I get permission errors. How can I end a...
1
by: DazedAndConfused | last post by:
Is it proper to structure your code in the basic work flow of the program? i.e. Form_Load
27
by: cj | last post by:
I run this program and to exit click the X in the upper right corner. But apparently it isn't really ending the program. If I return to VB and make changes then try to rebuild the app it says the...
4
by: DAL | last post by:
I want to build my kid a program that cycles through questions (using a label for the question), and lets him choose one of two radio buttons for the right answer. How do I get every set of...
1
by: John R. Dougherty | last post by:
I have written a VB.NET application, and want to be able to invoke it with parameters, to run without a user having to interact with it. I do still want to see any status messages the program...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
4
by: wesbland | last post by:
>From my understanding, when a string is stored in VB.NET and you look at it in the debugger, it has a quote on both sides to signify that it is a string as opposed to a char or int or whatever. ...
34
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.