Reputation: 2583
I have to read the C# volume serial number (the one provided when typing dir in a cmd prompt). That has always worked but today it is extremely slow.
[01.07.2024 12:54:35.415] I GetHdSerialString START
[01.07.2024 12:55:41.936] I GetHdSerialString END
so like more than one minute to get it.
The routine is the following
public static string GetHdSerialString()
{
try
{
WriteNLog("GetHdSerialString START ", eLogLevel.Info);
using ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk");
using ManagementObjectCollection mcol = mangnmt.GetInstances();
string result = "";
foreach (ManagementObject strt in mcol.Cast<ManagementObject>())
{
result += Convert.ToString(strt["VolumeSerialNumber"]);
break; //mi interessa solo il primo
}
result = result.Insert(4, "-");
WriteNLog("GetHdSerialString END ", eLogLevel.Info);
return result;
}
catch (Exception exc)
{
WriteNLog("GetHdSerialString exc:" + exc.Message, eLogLevel.Error);
return String.Empty;
}
}
Here is the point where it takes so long
Can anyone tell me why all of a sudden it takes so long and how to fix it?
I also tried other ways or retrieving that data but couldn't find any. Thanks Patrick
Upvotes: 0
Views: 74
Reputation: 2583
Actually the user "Good Night Nerd Pride" put me on the right track. As written in the comment above I tried some hw or driver causes but that was not the case. So I thought about the antivirus and without it that worked! Not sure why the antivirus is interfering with the hw management but as a matter of fact without it starting is immediate, with it it takes ages.
Upvotes: 1