資源簡介
獲得本機:
1.內存大小、內存使用率
2.CPU使用率
3.網絡適配器Kpbs,網絡使用率(類似與任務管理器中所看到的)
4.檢測指定端口是否被占用

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
namespace?GetInfo
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????try
????????????{
????????????????ImpComputerStatus?cmpSt?=?new?ImpComputerStatus();
????????????????Console.WriteLine(“Cpu?usage:{0}%!“?cmpSt.CpuUsage);
????????????????Console.WriteLine(“Physical?memory:{0}?M“?cmpSt.PhyMemory);
????????????????Console.WriteLine(“Memory?Usage:{0}?%“?cmpSt.MemoryUsage);
????????????????while?(true)
????????????????{
????????????????????Console.WriteLine(“Port?{0}?in?Use??{1}“?12345?cmpSt.PortInUse(12345));
????????????????????var?adptInfos?=?cmpSt.GetPhyNetAdapterInfos();
????????????????????foreach?(PhyNetAdapterInfo?adpt?in?adptInfos)
????????????????????{
????????????????????????Console.WriteLine(“Adapter[{0}]Kbps:{1};NetUsage:{2}%“?adpt.PhyNetName?adpt.NetKbpsadpt.NetUsage);
????????????????????}
????????????????}
????????????}
????????????catch?(System.Exception?ex)
????????????{
????????????????Console.WriteLine(“{0}“?ex.Message);
????????????????return;
????????????}
????????????return;
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-08-05?13:16??GetInfo\
?????目錄???????????0??2015-08-05?13:18??GetInfo\GetInfo\
?????文件?????????911??2015-08-05?13:16??GetInfo\GetInfo.sln
?????文件???????40960??2015-08-07?23:44??GetInfo\GetInfo.v11.suo
?????文件?????????187??2015-08-05?13:16??GetInfo\GetInfo\App.config
?????目錄???????????0??2015-08-05?13:16??GetInfo\GetInfo\bin\
?????目錄???????????0??2015-08-05?14:05??GetInfo\GetInfo\bin\Debug\
?????文件????????9728??2015-08-07?13:29??GetInfo\GetInfo\bin\Debug\GetInfo.exe
?????文件?????????187??2015-08-05?13:16??GetInfo\GetInfo\bin\Debug\GetInfo.exe.config
?????文件???????22016??2015-08-07?13:29??GetInfo\GetInfo\bin\Debug\GetInfo.pdb
?????文件???????22984??2015-08-07?13:17??GetInfo\GetInfo\bin\Debug\GetInfo.vshost.exe
?????文件?????????187??2015-08-05?13:16??GetInfo\GetInfo\bin\Debug\GetInfo.vshost.exe.config
?????文件?????????490??2015-07-10?19:01??GetInfo\GetInfo\bin\Debug\GetInfo.vshost.exe.manifest
?????文件????????2691??2015-08-05?14:05??GetInfo\GetInfo\GetInfo.csproj
?????目錄???????????0??2015-08-05?13:16??GetInfo\GetInfo\obj\
?????目錄???????????0??2015-08-07?13:29??GetInfo\GetInfo\obj\Debug\
?????文件????????6867??2015-08-05?14:00??GetInfo\GetInfo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件?????????592??2015-08-07?13:17??GetInfo\GetInfo\obj\Debug\GetInfo.csproj.FileListAbsolute.txt
?????文件????????2058??2015-08-05?14:05??GetInfo\GetInfo\obj\Debug\GetInfo.csprojResolveAssemblyReference.cache
?????文件????????9728??2015-08-07?13:29??GetInfo\GetInfo\obj\Debug\GetInfo.exe
?????文件???????22016??2015-08-07?13:29??GetInfo\GetInfo\obj\Debug\GetInfo.pdb
?????文件???????????0??2015-08-05?13:16??GetInfo\GetInfo\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件???????????0??2015-08-05?13:16??GetInfo\GetInfo\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件???????????0??2015-08-05?13:16??GetInfo\GetInfo\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????目錄???????????0??2015-08-05?13:16??GetInfo\GetInfo\obj\Debug\TempPE\
?????文件????????1248??2015-08-07?13:18??GetInfo\GetInfo\Program.cs
?????目錄???????????0??2015-08-05?13:16??GetInfo\GetInfo\Properties\
?????文件????????1426??2015-08-05?13:16??GetInfo\GetInfo\Properties\AssemblyInfo.cs
?????文件????????6988??2015-08-07?13:28??GetInfo\GetInfo\SystemInfo.cs
- 上一篇:C#微秒級計時器
- 下一篇:C#小型窗體項目-BMI計算器
評論
共有 條評論