Skip to content

Commit e0e445e

Browse files
SteveL-MSFTTravisEz13
authored andcommitted
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)
1 parent 56f1db3 commit e0e445e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Microsoft.WSMan.Management/ConfigProvider.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public sealed partial class WSManConfigProvider : NavigationCmdletProvider, ICmd
3030
//Plugin Name Storage
3131
private PSObject objPluginNames = null;
3232

33+
private ServiceController winrmServiceController;
34+
3335
/// <summary>
3436
/// Determines if Set-Item user input type validation is required or not.
3537
/// 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)
44364438
/// <returns></returns>
44374439
private bool IsWSManServiceRunning()
44384440
{
4439-
ServiceController svc = new ServiceController("WinRM");
4440-
if (svc != null)
4441+
if (winrmServiceController == null)
44414442
{
4442-
if (svc.Status.Equals(ServiceControllerStatus.Running))
4443-
{
4444-
return true;
4445-
}
4443+
winrmServiceController = new ServiceController("WinRM");
44464444
}
4447-
return false;
4445+
else
4446+
{
4447+
winrmServiceController.Refresh();
4448+
}
4449+
4450+
return (winrmServiceController.Status.Equals(ServiceControllerStatus.Running));
44484451
}
44494452

44504453
/// <summary>

0 commit comments

Comments
 (0)