locked
Problem about Closing VB.Net Application RRS feed

  • 問題

  • Hi

    I am having problem on closing my VB.Net Application by clicking on the close button on the Top right hand conera of the application.

    I have 2 form on my VB.Net Windows Application E.g. "A","B", The application will start up with form "A" first, then The user may click on a button, then it will make Form "A" hidden by using the following Code
    Me.Close()
    B.Show()


    When I click on the Close "X" button on Form "B", it just close the form, but when I check the Task manager, the VB.NET Application still on the process list.

    Could you give me some suggestion about how could I Close the VB.NET Application when I click on the Close "X" button.

    Thanks in advance.
    2008年5月14日 15:06

解答

  • Hello ChiYau,

     

    Have you ever tried to call Appliction.Exit() method on FormClosed Event?

     

    Code Snippet

    private void Form2_FormClosed(object sender, FormClosedEventArgs e)

            {

                Application.Exit();

            }

     

     

     

    Hope this helps

    Wen Yuan

    2008年5月14日 16:01
  • Hi ArtCh

    Have you tried to use Environment.Exit(0)
    This may solve your problem

    Environment.Exit()
    Terminates this process and gives the underlying operating system the specified exit code.

    Application.Exit
    Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.

    The following links explains better about the different between Environment.Exit and Application.Exit
    http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-csharp/70655/Application-Exit-vs-Environmrnt-Exit-0

    Good luck
    2008年8月20日 20:18

所有回覆

  • Hello ChiYau,

     

    Have you ever tried to call Appliction.Exit() method on FormClosed Event?

     

    Code Snippet

    private void Form2_FormClosed(object sender, FormClosedEventArgs e)

            {

                Application.Exit();

            }

     

     

     

    Hope this helps

    Wen Yuan

    2008年5月14日 16:01
  • Hi Wen Yuan

    Thanks for your information,

    It works.

    Many thanks
    2008年5月15日 7:53
  • Hello,

     

    I have a follow up question to this thread if that is OK? I have two forms; let's call Form A and Form B.

     

    I click button on Form A to open Form B by:

     

    FormB.Show()

    Me.Hide()

     

    On Form B, after doing some things hits a button and hides and opens Form A again by:

     

    FormA.Show()

    Me.Hide()

     

    On Form A, I hit a 'Quit' button to close app by:

     

    Application.Exit()

     

    But Task Manager process list still appears. Can someone explain why and how to fix?

     

    Thanks in advance.....

     

    2008年8月20日 18:30
  • Hi ArtCh

    Have you tried to use Environment.Exit(0)
    This may solve your problem

    Environment.Exit()
    Terminates this process and gives the underlying operating system the specified exit code.

    Application.Exit
    Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.

    The following links explains better about the different between Environment.Exit and Application.Exit
    http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-csharp/70655/Application-Exit-vs-Environmrnt-Exit-0

    Good luck
    2008年8月20日 20:18