mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
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:
1 parent
56f1db33d3
commit
e0e445e88b
1 file changed
+10
-7
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user