none
My.Application RRS feed

  • Question

  • Hello,

    Please help me understand the My.Application object.

    I am writing code in the MyApplication_Startup method of a Windows Forms app:

    Private Sub MyApplication_Startup(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

    I would like to shutdown the application from code.

    I am trying this :

    Application.Exit

    But it won't even compile. It seems the "Application" object is not a Windows.Forms.Application object. So what is it ?

    And how may I shutdown the application ?

    Thanks

    Friday, March 14, 2014 10:34 AM

Answers

  • Hi, please try

    Windows.Forms.Application.Exit()
    

    if no Windows.Froms prefix, the Application object is My.Application, and there is no Exit method in My.Application object, so it you will see compile error.

    But Windows.Forms.Application.Exit() will not work in StartUp event, if you want to exit the code from StartUp event, you can try this:

    Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
         e.Cancel = True
    End Sub

    • Marked as answer by Sygrien Sunday, March 16, 2014 5:05 PM
    Saturday, March 15, 2014 3:12 PM