mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +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:
@@ -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