2011-11-09 5 views
0

표시하지 않습니다 나는이 시도 그런 thisthisASP.NET은 : PerformanceCounter는</p> <p>... 나는 등 asp.net, C#을에 완전한 초보자입니다 아무것도

을 보았다 :

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() + "%"); 

엄격 응용 프로그램을 콘솔되지 않은 응용 프로그램 유형을 가질 수 있지만 연관된 콘솔은 명시 적으로 만들어지지 않으면 볼 수 없으며 웹 응용 프로그램에있을 수 없습니다.

+0

오그 그 자체가 너무 분명해서 Response.Write를 사용하기 전에 ... 도움을 주셔서 감사합니다. –