• 大小: 0.04M
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-02-27
  • 语言: C#
  • 标签: 系统资源  C#  windows  

资源简介

C#获取CPU以及内存使用率的程序,有源码,使用Visual Studio 2013编译以及在Windows 8下调试。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            PerformanceCounter cpuCounter;
            PerformanceCounter ramCounter;
            cpuCounter = new PerformanceCounter();
            cpuCounter.CategoryName = “Processor“;
            cpuCounter.CounterName = “% Processor Time“;
            cpuCounter.InstanceName = “_Total“;
            cpuCounter = new PerformanceCounter(“Processor“ “% Processor Time“ “_Total“);
            ramCounter = new PerformanceCounter(“Memory“ “Available MBytes“);
            if ((int)cpuCounter.NextValue() > 80)
            {
                System.Threading.Thread.Sleep(1000 * 60);
            }
            Decimal a b c;
            a = Convert.ToDecimal(FormatSize(GetTotalPhys()));//得到内存已用大小
            b = Convert.ToDecimal(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-03-08 15:00  ConsoleApplication5\
     目录           0  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5\
     文件        2528  2020-03-09 15:12  ConsoleApplication5\ConsoleApplication5\ConsoleApplication5.csproj
     文件        4579  2020-03-09 15:27  ConsoleApplication5\ConsoleApplication5\Program.cs
     目录           0  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5\Properties\
     文件        1362  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5\Properties\AssemblyInfo.cs
     文件         163  2020-03-09 15:12  ConsoleApplication5\ConsoleApplication5\app.config
     目录           0  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5\bin\
     目录           0  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5\bin\Debug\
     文件        6656  2020-03-09 15:27  ConsoleApplication5\ConsoleApplication5\bin\Debug\ConsoleApplication5.exe
     文件         163  2020-03-09 15:12  ConsoleApplication5\ConsoleApplication5\bin\Debug\ConsoleApplication5.exe.config
     文件       15872  2020-03-09 15:27  ConsoleApplication5\ConsoleApplication5\bin\Debug\ConsoleApplication5.pdb
     文件       24216  2020-03-09 15:35  ConsoleApplication5\ConsoleApplication5\bin\Debug\ConsoleApplication5.vshost.exe
     文件         163  2020-03-09 15:12  ConsoleApplication5\ConsoleApplication5\bin\Debug\ConsoleApplication5.vshost.exe.config
     文件         490  2013-06-18 20:28  ConsoleApplication5\ConsoleApplication5\bin\Debug\ConsoleApplication5.vshost.exe.manifest
     目录           0  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5\obj\
     目录           0  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5\obj\Debug\
     文件         592  2020-03-09 15:35  ConsoleApplication5\ConsoleApplication5\obj\Debug\ConsoleApplication5.csproj.FileListAbsolute.txt
     文件        1270  2020-03-09 15:16  ConsoleApplication5\ConsoleApplication5\obj\Debug\ConsoleApplication5.csprojResolveAssemblyReference.cache
     文件        6656  2020-03-09 15:27  ConsoleApplication5\ConsoleApplication5\obj\Debug\ConsoleApplication5.exe
     文件       15872  2020-03-09 15:27  ConsoleApplication5\ConsoleApplication5\obj\Debug\ConsoleApplication5.pdb
     文件        6249  2020-03-09 15:12  ConsoleApplication5\ConsoleApplication5\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2020-03-09 15:55  ConsoleApplication5\ConsoleApplication5\obj\Debug\TempPE\
     文件           0  2020-03-08 15:14  ConsoleApplication5\ConsoleApplication5\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2020-03-08 15:14  ConsoleApplication5\ConsoleApplication5\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2020-03-08 15:14  ConsoleApplication5\ConsoleApplication5\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     文件        1026  2020-03-08 15:00  ConsoleApplication5\ConsoleApplication5.sln
     文件       28160  2020-03-09 15:29  ConsoleApplication5\ConsoleApplication5.v12.suo

评论

共有 条评论