Ask Your Question
4

What is the way to retrieve a list of ongoing processes in a C# GUI application exclusively?

asked 2021-07-25 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-04-02 14:00:00 +0000

ladyg gravatar image

One way to retrieve a list of ongoing processes in a C# GUI application is to use the Process class in the System.Diagnostics namespace. Here is an example code snippet:

using System.Diagnostics;

// retrieve a list of ongoing processes
Process[] processes = Process.GetProcesses();

// display the list in a ListBox control
foreach (Process process in processes)
{
    listBox1.Items.Add(process.ProcessName);
}

Note that this code retrieves all ongoing processes in the system, not just those associated with the current application. To filter the list to only include processes associated with the current application, you can use the GetCurrentProcess() method of the Process class:

// retrieve a list of ongoing processes associated with the current application
Process[] processes = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);

// display the list in a ListBox control
foreach (Process process in processes)
{
    listBox1.Items.Add(process.ProcessName);
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-25 11:00:00 +0000

Seen: 9 times

Last updated: Apr 02 '22