基于单声道的Microsoft.VisualBasic ComputerInfo替换

时间:2016-12-26 14:12:18

标签: c# mono

我跟随c#代码在visual studio中运行得非常好但是如果想在mono上编译它只是失败并且错误CmputerInfo不存在你是否缺少程序集引用。

// Get Total Available Memory Percentage and if its below a threshhold then send ServiceUnavailable
            ComputerInfo computerInfo = new ComputerInfo();
            ulong totalPhysicalMemory = computerInfo.TotalPhysicalMemory;
            ulong availablePhysicalMemory = computerInfo.AvailablePhysicalMemory;
            ulong availablePhysicalMemoryPercentage = (availablePhysicalMemory * 100 / totalPhysicalMemory);

如果单声道不支持上述dll。请告诉我如何在linux中收集上述信息。

由于

1 个答案:

答案 0 :(得分:1)

使用此作为替代:

var pc = new System.Diagnostics.PerformanceCounter("Mono Memory", "Available Physical Memory");
long availableMemory = pc.RawValue;
var pc2 = new System.Diagnostics.PerformanceCounter("Mono Memory", "Total Physical Memory");
long physicalMemory = pc2.RawValue;