本文整理汇总了C#中System.Diagnostics.PerformanceCounter.NextValue方法的典型用法代码示例。如果您正苦于以下问题:C# PerformanceCounter.NextValue方法的具体用法?C# PerformanceCounter.NextValue怎么用?C# PerformanceCounter.NextValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.PerformanceCounter
的用法示例。
在下文中一共展示了PerformanceCounter.NextValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCounterValue
public static String GetCounterValue(PerformanceCounter pPerformanceCounter)
{
String retval = "";
// Retrieve PerformanceCounter result based on its CounterType.
switch (pPerformanceCounter.CounterType)
{
case PerformanceCounterType.NumberOfItems32:
retval = pPerformanceCounter.RawValue.ToString();
break;
case PerformanceCounterType.NumberOfItems64:
retval = pPerformanceCounter.RawValue.ToString();
break;
case PerformanceCounterType.RateOfCountsPerSecond32:
retval = pPerformanceCounter.NextValue().ToString();
break;
case PerformanceCounterType.RateOfCountsPerSecond64:
retval = pPerformanceCounter.NextValue().ToString();
break;
case PerformanceCounterType.AverageTimer32:
retval = pPerformanceCounter.NextValue().ToString();
break;
default:
retval = null;
break;
}
return retval;
}
示例2: RAM_Count
public int RAM_Count()
{
PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes");
perfMemCount.NextValue();
short currentAvailableMemory = (short)perfMemCount.NextValue();
return currentAvailableMemory;
}
示例3: CPUUsage
private void CPUUsage()
{
Task.Factory.StartNew(() =>
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
cpuCounter.NextValue();
Thread.Sleep(20);
cpu = cpuCounter.NextValue();
while (true)
{
try
{
Thread.Sleep(1000);
cpu = cpuCounter.NextValue();
}
catch (Exception e)
{
ShowBalloon("CPU", e);
Thread.Sleep(10000);
}
}
});
}
示例4: Scheduler
/// <summary>
/// This method is responsible for monitoring system resource and user activity with the computer
/// And periodically changes the shared variable 'crawlerState'
/// </summary>
public void Scheduler()
{
PerformanceCounter pc = new PerformanceCounter("Processor", "% Idle Time", "_Total", true);
LASTINPUTINFO info = new LASTINPUTINFO();
info.cbSize = Marshal.SizeOf(typeof(LASTINPUTINFO));
while (GlobalData.RunScheduler)
{
if (GetLastInputInfo(ref info))
{
if ((Environment.TickCount - info.dwTime) / 1000 > 5 && (int)pc.NextValue() > 40)
{
crawlerState = CrawlerState.Run;
}
else
{
crawlerState = CrawlerState.Stop;
if ((Environment.TickCount - info.dwTime) / 1000 <= 5)
GlobalData.lIndexingStatus.Text = string.Format("Indexing is paused and will be resumed in {0} sec of computer inactivity [ CPU Idle : {1:F2}% ]", 5 - (Environment.TickCount - info.dwTime) / 1000, pc.NextValue());
}
}
Thread.Sleep(1000);
}
pc.Close();
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
PerformanceCounter cpuCounter = new PerformanceCounter();
PerformanceCounter ramCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
System.Threading.Thread.Sleep(1000);
cpuCounter.NextValue();
System.Threading.Thread.Sleep(1000);
Response.Write("Worker State: " + status + "<br>");
Response.Write("CPU Utilization: " + cpuCounter.NextValue() + " <br>");
Response.Write("RAM Utilization: " + ramCounter.NextValue() + " <br>");
Response.Write("Urls Crawled: " + " <br>");
Response.Write("Last 10 URLs crawled" + " <br>");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue urlQ = queueClient.GetQueueReference("pagequeue");
urlQ.CreateIfNotExists();
int? messageCount = urlQ.ApproximateMessageCount;
Response.Write(messageCount.ToString());
Debug.WriteLine("ApproximateMessageCount: " + urlQ.ApproximateMessageCount);
Response.Write("Size of Queue: " + urlQ.ApproximateMessageCount + " <br>");
Response.Write("Size of Index: " + " <br>");
Response.Write("Errors and URLs: " + " <br>");
}
示例6: CPUMonitoring
//Function will read and display current CPU usage
public static async void CPUMonitoring(TextBox usageTextBox, TextBox warningTextBox)
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
while (true)
{
//First value always returns a 0
var unused = cpuCounter.NextValue();
await Task.Delay(1000);
usageTextBox.Invoke(new Action(() =>
{
CPUCounter = cpuCounter.NextValue();
usageTextBox.Text = CPUCounter.ToString("F2") + "%";
}));
CPUCalculations();
CPUAnomalies.StartAnomalyDetection(warningTextBox);
if (mainMenu.done)
break;
}
}
示例7: Request
public byte[] Request(byte[] header)
{
string newheader = "HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n";
string processmsg = Encoding.UTF8.GetString(header);
if (processmsg.Contains(@"/status/all"))
{
PerformanceCounter cpuCounter = new PerformanceCounter("Processor Information", "% Processor Time");
PerformanceCounter ramCounter;
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
cpuCounter.NextValue();
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
string jsoncpu = "{\"cpu\" : \"" + cpuCounter.NextValue() + "%\"}";
string jsonmem = "{\"memory\" : \"" + ramCounter.NextValue() + "MB\"}";
string json = "[" + jsonmem + "," + jsoncpu + "]";
return System.Text.Encoding.UTF8.GetBytes(newheader + json);
}
return null;
}
示例8: CollectMetric
public float CollectMetric(PluginResource pluginResource, string option = null)
{
// get a handle on the service first
var service = ServiceController.GetServices().FirstOrDefault(s => s.DisplayName == option);
if (service == null)
{
throw new Exception(string.Format("Windows service by name '{0}' not found", option));
}
if (service.Status == ServiceControllerStatus.Stopped)
{
return default(float);
}
else if (pluginResource.ResourceTextKey == StatusResource)
{
return 1;
}
// get a handle on the process
var serviceMgtObj = new ManagementObject(@"Win32_Service.Name='" + service.ServiceName + "'");
var serviceProcess = Process.GetProcessById(Convert.ToInt32(serviceMgtObj["ProcessId"]));
// return perfomance counter value for process
var perfCounter = new PerformanceCounter("Process", pluginResource.Label, serviceProcess.ProcessName);
var value = perfCounter.NextValue();
if (value == 0.0)
{
Thread.Sleep(1000);
value = perfCounter.NextValue();
}
return value;
}
示例9: UpTime
public TimeSpan UpTime()
{
using (var uptime = new PerformanceCounter("System", "System Up Time"))
{
uptime.NextValue(); //Call this an extra time before reading its value
return TimeSpan.FromSeconds(uptime.NextValue());
}
}
示例10: GetPerformanceCounterUptime
// This sets the System uptime using the perf counters
// this gives the best result but on a system with corrupt perf counters
// it can freeze
internal void GetPerformanceCounterUptime()
{
using (var uptime = new PerformanceCounter("System", "System Up Time"))
{
uptime.NextValue();
Uptime = TimeSpan.FromSeconds(uptime.NextValue());
}
}
示例11: getSystemUpTime
private static TimeSpan getSystemUpTime()
{
using (var upTime = new PerformanceCounter("System", "System Up Time"))
{
upTime.NextValue();
return TimeSpan.FromSeconds(upTime.NextValue());
}
}
示例12: cpu
public string cpu()
{
var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
cpuCounter.NextValue();
Thread.Sleep(1000);
var usage = cpuCounter.NextValue();
return Convert.ToInt16(usage).ToString();
}
示例13: th_cpu
public static void th_cpu()
{
PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
float useless = cpuCounter.NextValue();
System.Threading.Thread.Sleep(100);
float cpuval = cpuCounter.NextValue();
Console.Out.WriteLine(cpuval);
}
示例14: getCoreUsage
//Get the CPU usage for the core passed in
public static int getCoreUsage(String core)
{
//Generate a new counter for core x
PerformanceCounter coreUsage = new PerformanceCounter("Processor", "% Processor Time", core);
coreUsage.NextValue();
System.Threading.Thread.Sleep(750);
int corePercentage = (int)coreUsage.NextValue();
return corePercentage;
}
示例15: TotalCPUAsync
async public Task<float> TotalCPUAsync()
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
cpuCounter.NextValue();
await Task.Delay(1000);
return cpuCounter.NextValue();
}