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

The Archive Base Latest Questions

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

First off, I am using my own Process Wrapper to hold the starting path

  • 0

First off, I am using my own Process Wrapper to hold the starting path of a process.

public class MCProcess()
{
       public Process Process { get; set;}
       public string  StartingPath { get; set;}

       public MCProcess(string start, Process p)
       {
             Process = p;
             StartingPath = start;
       }
}

Now, I keep have a List<MCProcces> called runningProcesses that I use to keep track of all the processes and starting paths of every process that my program has started.

For Example:

string path = "C:\\Windows\\System32\\notepad.exe";
Process temp = Process.Start(path);
runningProcesses.Add(new MCProcess(path, temp));

Now, sometimes, I want to close processes that I have run. Instead of looking through the task manager and trying to find the MainModuleName of each process that I started, I included the StartingPath for a reason.

If I want to close a notepad, I just loop through my runningProcesses, find out which process has the startingPath for notepad and then use Process.Kill to kill that process.

string path = "C:\\Windows\\System32\\notepad.exe";
for (int i = 0; i < runningProcesses.Count; i++)
{
     if (runningProcesses[i].StartingPath == path)
     {
          runningProcesses[i].Process.Kill();
          runningProcesses.RemoveAt(i);
     }
}

This code works beautiful on Windows 7 and I have had no issues at all. However, when using this on Windows XP, I get an ArgumentNullException with Process.Kill.

Is there something about the Process class that doesn’t make it work well on Windows XP?

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

    Amazed how this is working in win 7. You are modifying a collection while using it in loop. You should maintain index of processes to be deleted, and then once done with the loop, remove all the processes

    Try something like

    var processesToRemove = runningProcesses.Where (p => String.Equals(p.StartingPath, path);
    foreach(var process in processToRemove)
    {
      process.Process.Kill();
      runningProcesses.Remove(process);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off - I'm not using MapKit. I'm using my own controls for something
First off, I'm using XCode 4.0.2. Okay, here is my issue. I can build
First off, I'm using the Qt 4 libraries and C++. Is there a way
First off I want to say that I am not using threads or multiple
First off, let me clarify the platforms we are using. We have an ASP.NET
First off, here is the situation. I'm using a guild hosting site that allows
First off, I'm a complete beginner at C++. I'm coding something using an API,
I am using the Android Emulator to debug my application, first off it is
We're about to set off our first larger WCF project, and we're having some
First off I created my own theme from scratch. I've been trying to figure

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.