ProcessModelInfo.GetCurrentProcessInfo 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回執行目前要求的背景工作處理序的相關資訊。
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,含有關於目前處理序的資訊。
例外狀況
處理序資訊無法供目前要求使用。
範例
下列程式碼範例示範如何呼叫 GetCurrentProcessInfo 方法來顯示網頁上目前執行 ASP.NET 程式的相關統計資料。
<%@ 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 進程模型下執行的應用程式。