我是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
。为什么请?
答案 0 :(得分:1)
您正在写入无法正常工作的控制台,而是写入响应(就像您的字符串一样):
Response.Write(cpuload.NextValue().ToString() + "%");
虽然不是严格控制台应用程序的应用程序类型可以具有关联的控制台,但除非明确指出,否则它们不可见,并且不能在Web应用程序中。