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:
parent
56f1db33d3
commit
e0e445e88b
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue