Compartilhar via


Instrução End

Terminates execution immediately.

End

Comentários

Você pode colocar o Enddedemonstrativo em qualquer lugar em um procedimento para forçar o aplicativo inteiro para parar a execução. EndFecha todos os arquivos abertos com um Opendedemonstrativo e limpa todos os aplicativodo variáveis. The application closes as soon as there are no other programs holding references to its objects and none of its code is running.

ObservaçãoObservação

The End statement stops code execution abruptly, and does not invoke the Dispose 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.

The Stop statement suspends execution, but unlike End, it does not close any files or clear any variables, unless it is encountered in a compiled executable (.exe) file.

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 (Instrução Return (Visual Basic) and Declaração Saída (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.

Observação de segurançaObservação sobre segurança

O Endchamadas dedemonstrativo a Exitométodo do Environmentclasse a Systemnamespace. Exitrequer que você tenha UnmanagedCode permissão. If you do not, a SecurityException error occurs.

When followed by an additional keyword, Instrução End <keyword> (Visual Basic) delineates the end of the definition of the appropriate procedure or block. For example, End Function terminates the definition of a Function procedure.

Exemplo

The following example uses the End statement to terminate code execution if the user requests it.

Sub Form_Load()
  Dim answer As MsgBoxResult
  answer = MsgBox("Do you want to quit now?", MsgBoxStyle.YesNo)
  If answer = MsgBoxResult.Yes Then
      MsgBox("Terminating program")
      End
  End If
End Sub

Smart Device Developer Notes

This statement is not supported.

Consulte também

Referência

Instrução Stop (Visual Basic)

Instrução End <keyword> (Visual Basic)

SecurityPermissionFlag