Fix perf issue in provider by using Refresh() to update the status rather than instantiating ServiceController which has a significant perf degradation from .NET Framework (#7680)

This commit is contained in:
Steve Lee
2018-09-04 10:00:16 -07:00
committed by Aditya Patwardhan
parent eb92b14433
commit b99fde0389
@@ -30,6 +30,8 @@ namespace Microsoft.WSMan.Management
//Plugin Name Storage
private PSObject objPluginNames = null;
private ServiceController winrmServiceController;
/// <summary>
/// Determines if Set-Item user input type validation is required or not.
/// It is True by default, Clear-Item will set it to false so that it can
@@ -4436,15 +4438,16 @@ namespace Microsoft.WSMan.Management
/// <returns></returns>
private bool IsWSManServiceRunning()
{
ServiceController svc = new ServiceController("WinRM");
if (svc != null)
if (winrmServiceController == null)
{
if (svc.Status.Equals(ServiceControllerStatus.Running))
{
return true;
}
winrmServiceController = new ServiceController("WinRM");
}
return false;
else
{
winrmServiceController.Refresh();
}
return (winrmServiceController.Status.Equals(ServiceControllerStatus.Running));
}
/// <summary>