An unhandled exception of type 'System.FormatException' occurred in mscorlib.dllAdditional information: The input string was not in an incorrect format.
and break in this line:
double ram = Convert.ToInt32(Program.HardwareInfo.RAM());
Form1.cs
PerformanceCounter ram = new PerformanceCounter("Memory", "Available MBytes", null);
public string RAM_TIE()
{
float ran = ram.NextValue();
int run = (int)ran;
return run.ToString();
}
public string RAMU_TIE()
{
int ramu = Convert.ToInt32(RAM_TIE());
double ram = Convert.ToInt32(Program.HardwareInfo.RAM());
double sub = ram - ramu;
return sub.ToString();
}
Program.cs
public static string RAM()
{
ManagementScope oMs = new ManagementScope();
ObjectQuery oQuery = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oCollection = oSearcher.Get();
long MemSize = 0;
long mCap = 0;
//
foreach (ManagementObject obj in oCollection)
{
mCap = Convert.ToInt64(obj["Capacity"]);
MemSize += mCap;
}
MemSize = (MemSize / 1024) / 1024;
return MemSize.ToString() + "MB";
}