How to determine if a program (Process) is running and get an instance of it in a Windows 8.1 Universal app

I'm new to the world of Windows Universal Apps, but I find this a very interesting field, so I wanted to start learning about its capabilities.

I am currently a WPF.NET developer and I want to check if a program is currently running and get an instance of it. In WPF, I would do it with Process.GetProcessesByName () , but the process is not available in a generic app. Is there a similar way to get a process (running a program instance) in Windows 8.1 Universal App?

+3


source to share


2 answers


System.Diagnostics.Process is not available in a UWP app. These applications are isolated and cannot view other processes running on the machine.



+3


source


Add this line to your usage list:

using System.Diagnostics;

      

You can now get the list of processes using the Process.GetProcesses () method, as shown in this example:



Process[] processlist = Process.GetProcesses();

foreach(Process theprocess in processlist){
Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
}

      

Some interesting properties of the Process object that you might also need:

p.StartTime (Shows the time the process started)
p.TotalProcessorTime (Shows the amount of CPU time the process has taken)
p.Threads ( gives access to the collection of threads in the process)

      

+1


source







All Articles