473,669 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Exi t(), but neither will just end the program there
and then. Instead, both allow Form_Load to continue.
Mar 25 '08 #1
4 1916
On Tue, 25 Mar 2008 14:09:52 -0700, Dom <do********@gma il.comwrote:
How do I end a program while in Form_Load? I tried both this.Close(),
and Application.Exi t(), 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.Exi t(). That would prevent the
rest of your Load event handler from executing.

The Application.Exi t() 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.co m>
wrote:
>I'm not aware of a .NET equivalent to "exit()" [...]

Environment.Exi t() 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...@nn owslpianmk.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
1495
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 module I have: Dim Form As New Form1 Sub main()
1
3944
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 program when running from the web ?
1
1209
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
2071
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 exe is still in use--I find it is still a process in Task Manager. What do I need to do to make clicking that X actually end the program? Public Class Form1 Inherits System.Windows.Forms.Form
4
7462
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 questions and answers to cycle through until the last question? Also, how can I give him the score after the last question. Thank you in advance. DAL. P.S. As a beginner, I figured I couldn't pass up the chance to learn something new, and to practice...
1
2785
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 generates (dialog boxes are suppressed in this mode, but there are still counters, etc. that display). I am currently invoking the functions of the program from the Form_Load procedure - then ultimately, the program is closed from here also, when in...
10
10036
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 believe that this has to do with unreleased form component events or event handlers. I'm comparatively new to .net and windows forms, in the sense that though I've been using them for over 2 years now, it's been rather sporadic. I work with...
4
2184
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. I've got a simple program here (I actually found it on the web somewhere, but I'm looking through it) that doesn't seem to have that ending quote at when it gets down to the end. In this program it doesn't make much of a difference, but I've...
34
2727
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 constant: i.e. five or the string is abc????? xyz How can i generalize it for any length of the string?
0
8465
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...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8803
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8587
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,...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
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.