VB .NET (6) Console APP windows do not close automatically

BenoitB 1 Reputation point
2022-11-16T11:50:21.347+00:00

Hello,

Since I work with Visual Studio 2022, framework .NET 6.0, my console applications do not close when I run the application exe, the "black" window remains
open and I am forced to close with the cross in the upper right corner.

Can anyone help me? An option in the Visual Studio? A command to run to close this window and stop the application completely?
Thanks in advance for your help.
Ben

Developer technologies | .NET | .NET Runtime
{count} votes

3 answers

Sort by: Most helpful
  1. BenoitB 1 Reputation point
    2022-11-16T15:15:20.587+00:00

    No, not in debugging.
    Only when I run EXE file.

    I've seen some people put the following statement at the end of the code to terminate all streams :

    Environment.Exit(0)

    Indeed, this ends my application well. But is this really what should be added?

    0 comments No comments

  2. Michael Taylor 60,326 Reputation points
    2022-11-16T15:18:00.853+00:00

    Can you provide us a screenshot? How are you running your app? Are you double clicking the EXE from File Explorer? Are you running the app in VS (which is in the debugger even if you aren't stepping through your code)? Please provide more information.

    0 comments No comments

  3. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2022-11-17T03:01:52.83+00:00

    Hi @BenoitB ,
    You can use Environment.Exit(0) if you can make sure that the application should be closed, such as using threads for monitoring.

    But it's best to check what in your code is preventing the command line window from closing, and perhaps you can provide a piece of code that allows us to reproduce the problem.

    Can your application shut down gracefully when running in debug mode?
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.