fix获取磁盘信息失败报错

This commit is contained in:
不做码农 2022-05-26 12:55:13 +08:00
parent 26566300cc
commit 1999872d73

View File

@ -76,6 +76,8 @@ namespace Infrastructure
{
var driv = DriveInfo.GetDrives();
foreach (var item in driv)
{
try
{
var obj = new DiskInfo()
{
@ -88,6 +90,12 @@ namespace Infrastructure
obj.AvailablePercent = decimal.Ceiling(obj.Used / (decimal)obj.TotalSize * 100);
diskInfos.Add(obj);
}
catch (Exception ex)
{
Console.WriteLine("获取磁盘信息出错了" + ex.Message);
continue;
}
}
}
return diskInfos;