From 64e8381e38db4e7a8172e903cb59597af5214722 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL)" Date: Fri, 31 Aug 2018 14:15:53 -0700 Subject: [PATCH] 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 --- .../ConfigProvider.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index 3a60621f5fb..576184f83a4 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -30,6 +30,8 @@ public sealed partial class WSManConfigProvider : NavigationCmdletProvider, ICmd //Plugin Name Storage private PSObject objPluginNames = null; + private ServiceController winrmServiceController; + /// /// 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 @@ private void AssertError(string ErrorMessage, bool IsWSManError) /// 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)); } ///