查看系统当前进程使用情况
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
public partial class Member_Login_test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Button1.Click += new EventHandler(Button1_Click);
this.listBox1.SelectedIndexChanged+=new EventHandler(listBox1_SelectedIndexChanged);
}
void Button1_Click(object sender, EventArgs e)
{
//获取系统当前所有进程
this.listBox1.Items.Clear();
Process[] MyProcesses = Process.GetProcesses();
foreach (Process MyProcess in MyProcesses)
{
this.listBox1.Items.Add(MyProcess.ProcessName);
}
this.listBox1.SelectedIndex = 0;
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{//显示选择的系统进程详细信息
try
{
string ProcessName = this.listBox1.Text;
this.groupBox2.Text = ProcessName + "进程的详细信息";
Process[] MyProcess = Process.GetProcessesByName(ProcessName);
this.label1.Text = "进程映像名:" + MyProcess[0].ProcessName;
this.label2.Text = "进程ID:" + MyProcess[0].Id;
this.label3.Text = "启动线程数:" + MyProcess[0].Threads.Count.ToString();
this.label4.Text = "CPU占用时间:" + MyProcess[0].TotalProcessorTime.ToString();
this.label5.Text = "线程优先级:" + MyProcess[0].PriorityClass.ToString();
this.label6.Text = "启动时间:" + MyProcess[0].StartTime.ToLongTimeString();
this.label7.Text = "专用内存:" + (MyProcess[0].PrivateMemorySize / 1024).ToString() + "K";
this.label8.Text = "峰值虚拟内存:" + (MyProcess[0].PeakVirtualMemorySize / 1024).ToString() + "K";
this.label9.Text = "峰值分页内存:" + (MyProcess[0].PeakPagedMemorySize / 1024).ToString() + "K";
this.label10.Text = "分页系统内存:" + (MyProcess[0].PagedSystemMemorySize / 1024).ToString() + "K";
this.label11.Text = "分页内存:" + (MyProcess[0].PagedMemorySize / 1024).ToString() + "K";
this.label12.Text = "未分页系统内存:" + (MyProcess[0].NonpagedSystemMemorySize / 1024).ToString() + "K";
this.label13.Text = "物理内存:" + (MyProcess[0].WorkingSet / 1024).ToString() + "K";
this.label14.Text = "虚拟内存:" + (MyProcess[0].VirtualMemorySize / 1024).ToString() + "K";
}
catch (Exception Err)
{
//不处理产生的异常
}
}
}
前端代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="Member_Login_test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:button ID="Button1" runat="server" text="Button" />
<table>
<tr>
<td>
<asp:ListBox ID="listBox1" runat="server" AutoPostBack="true" Height="252px" Width="195px"></asp:ListBox>
</td>
<td rowspan="2">
<asp:TextBox ID="groupBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td><asp:Label id="label1" runat="server"></asp:Label></td>
<td><asp:Label id="label2" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
<td><asp:Label id="label3" runat="server"></asp:Label></td>
<td><asp:Label id="label4" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
<td><asp:Label id="label5" runat="server"></asp:Label></td>
<td><asp:Label id="label6" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
<td><asp:Label id="label7" runat="server"></asp:Label></td>
<td><asp:Label id="label8" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
<td><asp:Label id="label9" runat="server"></asp:Label></td>
<td><asp:Label id="label10" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
<td><asp:Label id="label11" runat="server"></asp:Label></td>
<td><asp:Label id="label12" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
<td><asp:Label id="label13" runat="server"></asp:Label></td>
<td><asp:Label id="label14" runat="server"></asp:Label></td>
</tr>
</table>
</div>
</form>
</body>
</html>