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

  • Home
  • SEARCH
  • 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 9253257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:10:24+00:00 2026-06-18T11:10:24+00:00

there a lots of different examples floating around SO using mutex , Environment.Exit(0) (Console

  • 0

there a lots of different examples floating around SO using mutex, Environment.Exit(0) (Console app), Application.Exit() (Win forms) and lot’s of post saying not to use process.kill().

Could someone explain the political incorrectness of how I am closing OTHER instances of my application. It is a windows forms app. This appears to be working perfectly on my local environment, but I am scared that there are some robust issues I am not aware of.

    // I get the current process name and ID
    string currentProcName = Process.GetCurrentProcess().ProcessName;
    int currentProcID = Process.GetCurrentProcess().Id;

    // I then get a list of all process running under this name
    Process[] currentProcess = Process.GetProcessesByName(currentProcName);

    foreach (Process proc in currentProcess)
    {
        // if the found process id is using the same name, but not this current id, kill it.
        if (proc.Id != currentProcID)
        {

            proc.Kill(); // Documentation says it imediatly stops the associated process.
            proc.Close(); // Documentation says that it frees all resources associated with this component

        }
    }  

As per documentation, I would think this is a reasonable way to close OTHER instances of the running application. Could some more experienced point out some issues if their is any? Aside from atomicity, as I will add in exception handling.

  • 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-18T11:10:25+00:00Added an answer on June 18, 2026 at 11:10 am

    I must defer to Raymond Chen here for reference:

    • Why can’t you trap TerminateProcess?
    • Further discussion on Killing a process vs. closing it

    Closing a process in a cooperative manner is by far the best way to get rid of it: It allows for the proper shutdown/closing to occur. Killing a process basically calls TerminateProcess, which flat-out stops whatever it is doing and kills the bugger.

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

Sidebar

Related Questions

In Ruby 1.9 there is a rich strftime function which enables lots of different
There are lots of tutorials/instructions on how to embed python in an application, but
I know there are lots of delegate/func examples but I can't find any examples
The problem is that there's going to be lots of different languages on our
There's lots of questions on SO related to this, but the ones I scanned
There's lots of good material on Design Patterns out there that covers how you
There are lots of implementations for validating Luhn checksums but very few for generating
There are lots of Fluent implementations out there now that work with Lambdas to
There are lots of java apps on my simulator menu screen which I have
There are lots written about the ReaderWriterLockSlim class which allows multiple read and 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.