using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//引用2命名空間
using System.Diagnostics;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Process[] p = Process.GetProcessesByName("devenv");//獲取指定進程信息
// Process[] p = Process.GetProcesses();//獲取所有進程信息
string cpu = string.Empty;
string info = string.Empty;
PerformanceCounter pp = new PerformanceCounter();//性能計數器
pp.CategoryName = "Process";//指定獲取計算機進程信息 如果傳Processor參數代表查詢計算機CPU
pp.CounterName = "% Processor Time";//占有率
//如果pp.CategoryName="Processor",那麼你這裡賦值這個參數 pp.InstanceName = "_Total"代表查詢本計算機的總CPU。
pp.InstanceName = "devenv";//指定進程
pp.MachineName = ".";
if (p.Length > 0)
{
foreach (Process pr in p)
{
while (true)//1秒鐘讀取一次CPU占有率。
{
info = pr.ProcessName + "內存:" +