2011-11-09 67 views
0

我在asp.net,C#等一個完整的初學者...ASP.NET:顯示的PerformanceCounter沒有

我看到thisthis

那我試試這個:

using System; 
using System.Configuration; 
using System.Data; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.IO; 
using System.Text; 
using System.Net; 
using System.Collections.Generic; 
using System.Xml; 

using System.Collections; 
using System.Collections.Specialized; 
using System.Diagnostics; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

     Response.Write("Hello from code behind"); 

     PerformanceCounter cpuload = new PerformanceCounter(); 
     cpuload.CategoryName = "Processor"; 
     cpuload.CounterName = "% Processor Time"; 
     cpuload.InstanceName = "_Total"; 

     //or PerformanceCounter cpuload = new PerformanceCounter("Processor", "% Processor Time", "_Total"); 

     Console.WriteLine(cpuload.NextValue() + "%"); 

    } 
} 

但是,只顯示Hello from code behind。告訴我爲什麼?

回答

1

你寫到控制檯,這是行不通的,寫入​​響應,而不是(就像你的字符串一樣):

Response.Write(cpuload.NextValue().ToString() + "%"); 

雖然應用程序類型不嚴格控制檯應用程序可以有一個關聯的控制檯,除非明確指出,否則它們是不可見的,並且不能在Web應用程序中。

+0

omg它是如此明顯,我之前使用Response.Write ...感謝您的幫助。 –