private void dataGridView1_SelectionChanged(object sender, EventArgs e) { try { string curpid = dataGridView1.CurrentRow.Cells["c_pid"].Value.ToString(); PortInfo p = curinfo.Find(delegate(PortInfo cp) { return(cp.PID.Equals(curpid)); }); lblinfo.Text = (string.IsNullOrEmpty(dataGridView1.CurrentRow.Cells["C_FileName"].Value.ToString()) ? "" : "关联文件:" + dataGridView1.CurrentRow.Cells["C_FileName"].Value.ToString() + "\r\n") + "启动时间:" + p.BindProcess.StartTime.ToLongTimeString() + "\r\n" + "占用时间:" + p.BindProcess.UserProcessorTime.TotalMinutes + "秒\r\n" + "专用内存大小:" + p.BindProcess.PrivateMemorySize64 / 1024 + "KB"; } catch { } }
private void 终止此进程KToolStripMenuItem_Click(object sender, EventArgs e) { try { if (dataGridView1.CurrentRow != null && MessageBox.Show("确定要关闭此进程?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { string curpid = dataGridView1.CurrentRow.Cells["c_pid"].Value.ToString(); PortInfo p = curinfo.Find(delegate(PortInfo cp) { return(cp.PID.Equals(curpid)); }); p.BindProcess.Kill(); System.Threading.Thread.Sleep(10); button1_Click(null, null); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void expandStringToList(List <string> source, List <PortInfo> p) { //记录表头信息 List <string> listindex = new List <string>(); foreach (string line in source) { try { if (string.IsNullOrEmpty(line)) { continue; } //获取第一行表头信息 if (listindex.Count <= 0) { if ((!line.ToLower().Contains("proto") && !line.ToLower().Contains("协议")) || !line.ToLower().Contains("pid")) { continue; } string[] strs = line.Split(' '); foreach (string str in strs) { if (string.IsNullOrEmpty(str) || str.ToLower().Trim() == "address" || listindex.Contains(str)) { continue; } listindex.Add(str); } } else { PortInfo pi = new PortInfo(); string[] infos = line.Split(' '); int index = 0; foreach (string v in infos) { if (string.IsNullOrEmpty(v)) { continue; } string key = listindex[index]; if (key.ToLower().Contains("proto") || key.ToLower().Contains("协议")) { pi.Proto = v; } else if (key.ToLower().Contains("pid")) { pi.PID = v; pi.BindProcess = getProcessByPID(v); } else if (key.ToLower().Contains("local") || key.ToLower().Contains("本地地址")) { string[] vs = v.Split(':'); pi.Local_Address = vs[0]; pi.Port = int.Parse(vs[1]); } else if (key.ToLower().Contains("foreign") || key.ToLower().Contains("外部地址")) { pi.Foreign_Address = v; } else if (key.ToLower().Contains("state") || key.ToLower().Contains("状态")) { int ptmp = 0; if (int.TryParse(v, out ptmp)) { pi.PID = v; pi.BindProcess = getProcessByPID(v); } else { pi.State = v; } } index++; } p.Add(pi); } } catch { } } }