首页 > 代码库 > C#获取WIN系统进程信息
C#获取WIN系统进程信息
private void button1_Click(object sender, EventArgs e) { listBox_thread_list.Items.Clear(); Process[] processes; processes = System.Diagnostics.Process.GetProcesses(); Process process; for (int i = 0; i < processes.Length; i++) { process = processes[i]; // str = str + Convert.ToString(process.Id) + ": "+process.ProcessName+"\r\n"; listBox_thread_list.Items.Add(process.Id + ":"+process.ProcessName); } //System.Windows.Forms.MessageBox.Show(str); // textBox_thread_list.Text = processes[0].ProcessName.ToString(); } private void get_this_thread_Click(object sender, EventArgs e) { string item = null; try { item = listBox_thread_list.SelectedItem.ToString(); }catch (ArgumentException e1) { throw new ArgumentException("出错啦!", e1); } string[] items = item.Split(new Char[]{‘:‘}); int thread_id = Convert.ToInt32(items[0]); string thread_name = items[1]; long thread_RAM = Process.GetProcessById(thread_id).WorkingSet64; using (var private_RAM = new PerformanceCounter("Process", "Working Set - Private", thread_name)) System.Windows.Forms.MessageBox.Show("线程ID:" + thread_id + "\n线程名:" + thread_name + "\n线程工作集:" + (thread_RAM) / 1024 + "Kb" + "\n线程专用内存:" + (private_RAM.NextValue() / 1024) + "Kb"); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。