I'm developing a small remote task manager application [server/client] on LAN using WCF service lib.
I need to know which way is faster to get processors information:
System.Diagnostics
?WMI
?I'm using the first options now, but if the application is x86, and the process is x64 then I can't access to Process.MainModule
, so it forces me to create two versions of my application to get it work on any PC, x86 version and x64.
So if I used WMI would I face the same issue?
public void GetProcesses()
{
foreach (Process p in Process.GetProcesses())
{
try
{
InfoProcess process = new InfoProcess(p.Id, p.MainModule.ModuleName, p.MainModule.FileVersionInfo.FileDescription, p.WorkingSet / 1024);
PrintProcess(process);
}
catch
{ }
}
}
public class InfoProcess
{
public int Id;
public string Name;
public string Description;
public int WorkingSet;
public InfoProcess(int Id, string Name, string Desc, int WorkingSet)
{
this.Id = Id;
this.Name = Name;
this.Description = Desc;
this.WorkingSet = WorkingSet;
}
}
If WMI is better, I need a little help with properties names that gives me:
Process.WorkingSet
Process.MainModule.FileVersionInfo.FileDescription
I would expect WMI to be slower. There are some tricks that you can use to speed up WMI, but in general, performance is often poor.
In your situation I would simply build your app targeting AnyCPU. Then you have a single app that runs as x86 under a 32 bit OS and as x64 under a 64 bit OS. That way you can avoid WMI altogether.