ProcessModelInfo.GetCurrentProcessInfo 方法

定义

返回有关执行当前请求的辅助进程的信息。Returns information about the worker process that is executing the current request.

public:
 static System::Web::ProcessInfo ^ GetCurrentProcessInfo();
public static System.Web.ProcessInfo GetCurrentProcessInfo ();
static member GetCurrentProcessInfo : unit -> System.Web.ProcessInfo
Public Shared Function GetCurrentProcessInfo () As ProcessInfo

返回

ProcessInfo

ProcessInfo,它包含有关当前进程的信息。A ProcessInfo that contains information about the current process.

例外

进程信息对于当前请求不可用。Process information is not available for the current request.

示例

下面的代码示例演示如何调用 GetCurrentProcessInfo 方法,以在网页上显示有关当前正在执行的 ASP.NET 进程的统计信息。The following code example demonstrates how to call the GetCurrentProcessInfo method to display statistics about the currently executing ASP.NET process on a Web page.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(object sender, EventArgs e)
{
    DataGrid1.DataSource = GetProcessInfoAsDataSet();
    DataGrid1.DataBind();
}

private DataSet GetProcessInfoAsDataSet()
{
    DataSet ds = new DataSet();
    ds.Tables.Add(new DataTable());
    ds.Tables[0].Columns.Add("ID",         typeof(string));
    ds.Tables[0].Columns.Add("Start Time", typeof(string));
    ds.Tables[0].Columns.Add("Age",        typeof (string));
    ds.Tables[0].Columns.Add("Request Count", typeof(string));
    ds.Tables[0].Columns.Add("Peak Memory",typeof(string));

    ProcessInfo info = ProcessModelInfo.GetCurrentProcessInfo();

    DataRow row = ds.Tables[0].NewRow();
    row["ID"]         = info.ProcessID;
    row["Start Time"] = info.StartTime;
    row["Age"]        = info.Age;
    row["Request Count"] = info.RequestCount;
    row["Peak Memory"]= info.PeakMemoryUsed;

    ds.Tables[0].Rows.Add(row);

    return ds;
}     
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataGrid 
            ID="DataGrid1" 
            runat="server" />    
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
    DataGrid1.DataSource = GetProcessInfoAsDataSet()
    DataGrid1.DataBind()
End Sub

Function GetProcessInfoAsDataSet() As DataSet
    Dim ds As New DataSet
    Dim dt As New DataTable
    ds.Tables.Add(dt)
    ds.Tables(0).Columns.Add("ID", GetType(String))
    ds.Tables(0).Columns.Add("Start Time", GetType(String))
    ds.Tables(0).Columns.Add("Age", GetType(String))
    ds.Tables(0).Columns.Add("Request Count", GetType(String))
    ds.Tables(0).Columns.Add("Peak Memory", GetType(String))

    Dim info As ProcessInfo 
    info = ProcessModelInfo.GetCurrentProcessInfo()

    Dim row As DataRow 
    row = ds.Tables(0).NewRow()
    
    row("ID")         = info.ProcessID
    row("Start Time") = info.StartTime
    row("Age")        = info.Age
    row("Request Count") = info.RequestCount
    row("Peak Memory")= info.PeakMemoryUsed

    ds.Tables(0).Rows.Add(row)
    Return ds
End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataGrid 
            ID="DataGrid1" 
            runat="server" />    
    </div>
    </form>
</body>
</html>

注解

GetCurrentProcessInfo方法仅适用于在 ASP.NET 进程模型下运行的应用程序。The GetCurrentProcessInfo method is applicable only for applications that are running under the ASP.NET process model.

适用于