|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Me.close vs. EndWhat is the difference between using Me.close vs. End to stop the
execution of a program? I've been using me.close and putting code in the form.closing event to make sure things are stopped before the program execution stops. This has been working for me even when the startup is sub main perhaps because my sub mail usually looks like <STAThread()> Public Sub main(ByVal CmdArgs() As String) Dim mainForm As New Form1 Application.Run(mainForm) End Sub cj wrote:
> What is the difference between using Me.close vs. End to stop the Even more so than in earlier incarnations of VB, you *should not use> execution of a program? End*. This is from the docs (my emphases): >> The End statement stops code execution abruptly, **without invoking theDispose or Finalize method**, or any other Visual Basic code. Object references held by other programs are invalidated. **If an End statement is encountered within a Try or Catch block, control does not pass to the corresponding Finally block.** Because End terminates your application without attending to any resources that might be open, **you should try to close down cleanly before using **it. For example, **if your application has any forms open, you should close them before control reaches the End statement.** **You should use End sparingly, and only when you need to stop immediately.** The normal ways to terminate a procedure (Return Statement (Visual Basic) and Exit Statement (Visual Basic)) not only close down the procedure cleanly but also give the calling code the opportunity to close down cleanly. A console application, for example, can simply Return from the Main procedure. **Security Note The End statement calls the Exit method of the Environment class in the System namespace. Exit requires that you have UnmanagedCode permission. If you do not, a SecurityException error occurs.** >> What you are doing is the right way to do things.> I've been using me.close and putting code in the form.closing event to > make sure things are stopped before the program execution stops. This > has been working for me even when the startup is sub main perhaps > because my sub mail usually looks like > > <STAThread()> Public Sub main(ByVal CmdArgs() As String) > Dim mainForm As New Form1 > Application.Run(mainForm) > End Sub -- Larry Lard Replies to group please cj,
Close is closing (let the program stop after all things done that are needed for that) End is killing (stop it at the place it is) Cor Show quoteHide quote "cj" <cj@nospam.nospam> schreef in bericht news:OjJwRaMhGHA.1320@TK2MSFTNGP04.phx.gbl... > What is the difference between using Me.close vs. End to stop the > execution of a program? > > I've been using me.close and putting code in the form.closing event to > make sure things are stopped before the program execution stops. This has > been working for me even when the startup is sub main perhaps because my > sub mail usually looks like > > <STAThread()> Public Sub main(ByVal CmdArgs() As String) > Dim mainForm As New Form1 > Application.Run(mainForm) > End Sub Cor Ligthert [MVP] wrote:
> cj, But doesn't Close just close the current Form? And if the current form> > Close is closing (let the program stop after all things done that are needed > for that) is not the main form for the application, the closing that form will not close the application. Don't you have to do a Close event in the main form to close the application? Show quoteHide quote > > End is killing (stop it at the place it is) > > Cor > > "cj" <cj@nospam.nospam> schreef in bericht > news:OjJwRaMhGHA.1320@TK2MSFTNGP04.phx.gbl... > > What is the difference between using Me.close vs. End to stop the > > execution of a program? > > > > I've been using me.close and putting code in the form.closing event to > > make sure things are stopped before the program execution stops. This has > > been working for me even when the startup is sub main perhaps because my > > sub mail usually looks like > > > > <STAThread()> Public Sub main(ByVal CmdArgs() As String) > > Dim mainForm As New Form1 > > Application.Run(mainForm) > > End Sub On 31 May 2006 12:47:19 -0700, za***@construction-imaging.com wrote:
> Have a look at the Application.Exit method>Cor Ligthert [MVP] wrote: >> cj, >> >> Close is closing (let the program stop after all things done that are needed >> for that) > >But doesn't Close just close the current Form? And if the current form >is not the main form for the application, the closing that form will >not close the application. Don't you have to do a Close event in the >main form to close the application? > Gene Zacks,.
If the mainform is the one that has its sub main in it (standard) than it has instanced all its subforms as objects and therefore close those as well. If you use an seperated Sub Main have than a look at the message from Gene about application exit. Cor <za***@construction-imaging.com> schreef in bericht Show quoteHide quote news:1149104839.116135.233350@u72g2000cwu.googlegroups.com... > > Cor Ligthert [MVP] wrote: >> cj, >> >> Close is closing (let the program stop after all things done that are >> needed >> for that) > > But doesn't Close just close the current Form? And if the current form > is not the main form for the application, the closing that form will > not close the application. Don't you have to do a Close event in the > main form to close the application? > >> >> End is killing (stop it at the place it is) >> >> Cor >> >> "cj" <cj@nospam.nospam> schreef in bericht >> news:OjJwRaMhGHA.1320@TK2MSFTNGP04.phx.gbl... >> > What is the difference between using Me.close vs. End to stop the >> > execution of a program? >> > >> > I've been using me.close and putting code in the form.closing event to >> > make sure things are stopped before the program execution stops. This >> > has >> > been working for me even when the startup is sub main perhaps because >> > my >> > sub mail usually looks like >> > >> > <STAThread()> Public Sub main(ByVal CmdArgs() As String) >> > Dim mainForm As New Form1 >> > Application.Run(mainForm) >> > End Sub > Hi,
Thank you for posting. When Form.Close() is called, the form is closed and all resources created within the object are closed and the form is disposed. The call of Form.Close() invokes the Form.Closing and Form.Closed events. If the form you are closing is the startup form of your application, your application ends. You can place the End statement anywhere in a procedure to force the entire application to stop running. The End statement stops code execution abruptly, without invoking the Dispose or Finalize method and the Form.Closed or Form.Closing event. If an End statement is encountered within a Try or Catch block, control does not pass to the corresponding Finally block.If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the End statement. Hope this is helpful to you. If you have any other concerns or need anything else, please don't hesitate to let me know. Sincerely, Linda Liu Microsoft Online Community Support ==================================================== When responding to posts,please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ====================================================
Opinion: VPN or Web Service?
Seeking report component.... AxWebBrowser problems in VS2005 C# to VB Conversion - 800 lines got - 2 lines beyond me Show dynamically selected row in datagridview custom panel control Assembly - Where did I come from? Determine caller class name Determine caller class name An Unhandled exception of type 'system.stackoverflowexception' occured in mscorlib.dll |
|||||||||||||||||||||||