0

This is the code i'm using:

List<Process> processes = Process.GetProcesses().ToList();
            processes.ForEach(x => MessageBox.Show(x.ProcessName + ".exe"));

For some reason, it is looping through it, I just want it to go through the processes once.

Anybody got any help?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by sknake
0

Your question doesn't make sense but based on the sample code I assume you want to show one message box with all of the processes? If that is the case call ShowProcessesGroup(); as shown below. ShowProcessesIndividually() is functionally identical to the code you posted.

private static void ShowProcessesIndividually()
    {
      Process[] procs = Process.GetProcesses();
      foreach (Process p in procs)
      {
        MessageBox.Show(p.ProcessName + ".exe");
      }
    }

    private static void ShowProcessesGroup()
    {
      System.Text.StringBuilder sb = new StringBuilder();
      Process[] procs = Process.GetProcesses();
      foreach (Process p in procs)
      {
        sb.AppendLine(p.ProcessName + ".exe");
      }
      MessageBox.Show(sb.ToString());
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.