Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7769651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:12:42+00:00 2026-06-01T16:12:42+00:00

How can I fire off a function when it detects the console closing when

  • 0

How can I fire off a function when it detects the console closing when using Environment.Exit(0)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:12:43+00:00Added an answer on June 1, 2026 at 4:12 pm

    The simplest way of doing this is probably to handle the AppDomain.ProcessExit event, which is raised when the application’s parent process exits.

    For example:

    Module MyApp
    
        Sub Main()
            ' Attach the event handler method
            AddHandler AppDomain.CurrentDomain.ProcessExit, AddressOf MyApp_ProcessExit
    
            ' Do something
            ' ...
    
            Environment.Exit(0)
        End Sub
    
        Private Sub MyApp_ProcessExit(sender As Object, e As EventArgs)
            Console.WriteLine("App Is Exiting...")
        End Sub
    
    End Module
    

    But calling Environment.Exit may not be the best solution to your original problem. In general, the only time it is necessary to use this method is when there might be other foreground threads running. And in that case, it’s worth investigating ways of gracefully terminating those other threads without resorting to draconian measures that kill the entire process.

    Environment.Exit, despite the somewhat pleasant-sounding name, is a pretty brutal measure. It’s not quite as bad as clicking “End Task” in the Windows Task Manager (and note that if you do that, the ProcessExit event will not be raised, meaning that the above suggestion will not work), but it’s probably not the solution you really want, either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this Jquery function for available username check. How can I fire this
I'm using getScript to fire a script when jquery has finished loading. $(document).ready(function() {
I have an MVC 3 app that is using jQuery AJAX to fire off
I have 2 places a user can click and both need to fire off
I needed a generic collection or list that can fire an event when an
I want to have a generic event that I can fire that will take
I have an event, which can fire itself. I try to make the code
How can one programmatically fire the SelectedIndexChanged event of a ListView? I've intended for
Is there anyway I can use native javascript to fire an event called onmove
Is there a WMI event you can subscribe to that will fire when a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.