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 8833103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:41:55+00:00 2026-06-14T08:41:55+00:00

So at the beginning of my program I have a piece of code that

  • 0

So at the beginning of my program I have a piece of code that checks to see if another instance of this process is running.

Process process = Process.GetCurrentProcess();
bool isProcessRunning = (Process.GetProcessesByName(process.ProcessName)).Length > 1;

If the the process is running then I open a message box that says the process is already running and asks the user if they want to terminate the current process and open a new one.

If the dialog result is yes then I use process.kill to close the process. The problem is I will have two of these processes running, so how do I specify which one to close? The process name will be exactly the same, and I want to close the one that was opened first.

  • 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-14T08:41:57+00:00Added an answer on June 14, 2026 at 8:41 am

    Loop through the processes with the same name and check if the Id is different. If it is, kill it.

    Process process = Process.GetCurrentProcess();
    var dupl = (Process.GetProcessesByName(process.ProcessName));
    if( dupl.Length > 1 && MessageBox.Show("Kill?", "Kill duplicates?", MessageBoxButtons.YesNo) == DialogResult.Yes ) {
        foreach( var p in dupl ) {
            if( p.Id != process.Id )
                p.Kill();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that shows a disclaimer at the beginning of the program.
I have a program that allows a user to type java code into a
I have a class called initialize that runs at the beginning of my program.
This is a test program that I have written for a larger project that
I have a PowerShell script that at the beginning of the program sets the
I have two lists A and B, at the beginning of my program, they
I am beginning to port a program which is written in C and have
I am just beginning to program in Java and I noticed that String is
In my current program I have a main window and a secondary window that
Background I have a program that has implemented the two classic taxes for Ontario

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.