[英]ASP.NET : PerformanceCounter displays nothing
我是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
顯示Hello from code behind
。 告訴我為什么?
您正在寫入無法使用的控制台,而是寫入響應(就像您的字符串一樣):
Response.Write(cpuload.NextValue().ToString() + "%");
雖然不是嚴格意義上的控制台應用程序的應用程序類型可以具有關聯的控制台,但是除非明確指定,否則它們是不可見的,並且不能在Web應用程序中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.