问题描述
你好.
我正在创建一个代码,以使用PerformanceCounter检查光盘驱动器(ODD)的性能.
I'm working on create a code to check the performance of Optical Disc Drive (ODD) with PerformanceCounter.
这是测试代码的一部分.
Here is a part of test code.
var cat = new System.Diagnostics.PerformanceCounterCategory("PhysicalDisk");
var instNames = cat.GetInstanceNames();
我将CategoryName用作"PhysicalDisk".和"LogicalDisk"但他们两个都无法检测到ODD.
I've used CategoryName as "PhysicalDisk" and "LogicalDisk" but both of them can't detect ODD.
仅检测硬盘.
是否可以将PerformanceCounter与ODD一起使用?
Is it impossible to use PerformanceCounter with ODD ?
我的错是什么?
推荐答案
感谢您在此处发布帖子,对您的回复表示歉意.
Thank you for posting here and sorry for late reply.
我测试了您的代码,就我而言,我也无法获得ODD.我获得了所有类别的名称,但是无法获得用于获得ODD的合适名称.
I test your code, on my side, I could not get the ODD as well. I get all the category name, however I could not get the suitable name to get the ODD.
您可以尝试另一种方式.
You could try another way.
static void Main(string[] args)
{
string strDVD;
try
{
string[] Drives = Directory.GetLogicalDrives();
foreach (var strDrive in Drives)
{
DriveInfo di = new DriveInfo(strDrive.Substring(0, 1).ToUpper());
if (di.DriveType == DriveType.CDRom)
{
strDVD = strDrive.Substring(0, 2);
Console.WriteLine(strDVD);
}
}
}
catch (Exception e)
{
MessageBox.Show("Error", e.Message);
}
Console.ReadKey();
}
我使用代码获取ODD,即DVD RW驱动器(D:).
I use the code to get the ODD, the DVD RW Drive (D:).
我希望这会有所帮助.
最好的问候,
温迪
这篇关于用于ODD(光盘驱动器)的C#PerformanceCounter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!