private Dictionary <int, ProcessViewModel> GetCurrentCpuTimes()
 {
     return((from p in SystemInformation.EnumProcesses()
             let id = p.Id
                      where id != 0
                      let process = NativeProcess.Open(ProcessAccessMask.QueryLimitedInformation, p.Id)
                                    select new {
         id,
         process.TotalTime,
         p.Name
     }).
            ToDictionary(pr => pr.id, pr => new ProcessViewModel {
         Name = pr.Name,
         TotalTime = pr.TotalTime,
         Id = pr.id
     }));
 }
Exemple #2
0
        static void Main(string[] args)
        {
            var processes = SystemInformation.EnumProcesses();

            foreach (var pi in processes)
            {
                Console.Write($"{pi.Name} ({pi.Id}) Threads: {pi.Threads} Parent: {pi.ParentId}");
                if (pi.Id > 0)
                {
                    try {
                        using (var process = NativeProcess.Open(ProcessAccessMask.QueryLimitedInformation, pi.Id)) {
                            Console.Write($" Start: {process.CreateTime}");
                        }
                    }
                    catch { }
                }
                Console.WriteLine();
            }
        }