我是Windows通用应用程序的新手,但我发现这是一个非常有趣的领域,所以我想开始了解它的功能。我目前是一个WPF .NET开发人员,我希望能够检查程序是否正在运行并获取其实例。在WPF中,我会使用Process.GetProcessesByName()来实现,但是在通用应用程序中,Process不可用。在Windows 8.1通用应用程序中,有没有类似的方法可以获取进程(正在运行程序的实例)?
在UWP应用程序中,System.Diagnostics.Process不可用。这些应用程序被沙箱化并且不允许查看运行在计算机上的其他进程。
using System.Diagnostics;
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
Process对象的一些有趣属性,这些属性也可能是必需的:
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)
Process
类。 - MrPaulch