more memory optimizations

#6-gpu-reporting
sleevezipper 4 years ago
parent 334929333e
commit 733e037276

@ -1,4 +1,4 @@
using hass_workstation_service.Communication; using hass_workstation_service.Communication;
using Serilog; using Serilog;
using Serilog.Core; using Serilog.Core;
using System; using System;
@ -73,19 +73,26 @@ namespace hass_workstation_service.Domain.Sensors
.Select(p => p.Id.ToString()) .Select(p => p.Id.ToString())
.ToHashSet(); .ToHashSet();
var REprocessid = new Regex(@"(?<=Handle="").*?(?="")", RegexOptions.Compiled); var REprocessid = new Regex(@"(?<=Handle="").*?(?="")", RegexOptions.Compiled);
int numberOfLogonSessionsWithExplorer = 1;
var numberOfLogonSessionsWithExplorer = new ManagementObjectSearcher(scope, new SelectQuery("SELECT * FROM Win32_SessionProcess")).Get() using (var managemntObjectSearcher = new ManagementObjectSearcher(scope, new SelectQuery("SELECT * FROM Win32_SessionProcess")))
.Cast<ManagementObject>() {
.Where(mo => explorerProcesses.Contains(REprocessid.Match(mo["Dependent"].ToString()).Value)) numberOfLogonSessionsWithExplorer = managemntObjectSearcher.Get()
.Select(mo => mo["Antecedent"].ToString()) .Cast<ManagementObject>()
.Distinct() .Where(mo => explorerProcesses.Contains(REprocessid.Match(mo["Dependent"].ToString()).Value))
.Count(); .Select(mo => mo["Antecedent"].ToString())
.Distinct()
.Count();
}
int numberOfUserDesktops = 1; int numberOfUserDesktops = 1;
// this can fail sometimes, that's why we set numberOfUserDesktops to 1 // this can fail sometimes, that's why we set numberOfUserDesktops to 1
try try
{ {
numberOfUserDesktops = new ManagementObjectSearcher(scope, new SelectQuery("select * from win32_Perfrawdata_TermService_TerminalServicesSession")).Get().Count - 1; // don't count Service desktop using (var managementObjectSearcher = new ManagementObjectSearcher(scope, new SelectQuery("select * from win32_Perfrawdata_TermService_TerminalServicesSession")))
{
numberOfUserDesktops = managementObjectSearcher.Get().Count - 1; // don't count Service desktop
}
} }
catch catch
{ {
@ -104,7 +111,9 @@ namespace hass_workstation_service.Domain.Sensors
return PCUserStatuses.LoggedOff; return PCUserStatuses.LoggedOff;
} }
else else
{
return PCUserStatuses.InUse; return PCUserStatuses.InUse;
}
} }
catch (Exception e) catch (Exception e)
{ {

Loading…
Cancel
Save