-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Fix list enumeration #11851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix list enumeration #11851
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1087,17 +1087,9 @@ internal List<ServiceController> DoStopService(ServiceController serviceControll | |
| /// True if all dependent services are stopped | ||
| /// False if not all dependent services are stopped | ||
| /// </returns> | ||
| private bool HaveAllDependentServicesStopped(ICollection<ServiceController> dependentServices) | ||
| private bool HaveAllDependentServicesStopped(ServiceController[] dependentServices) | ||
| { | ||
| foreach (ServiceController service in dependentServices) | ||
| { | ||
| if (service.Status != ServiceControllerStatus.Stopped) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| return Array.TrueForAll(dependentServices, service => service.Status == ServiceControllerStatus.Stopped); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -1106,14 +1098,10 @@ private bool HaveAllDependentServicesStopped(ICollection<ServiceController> depe | |
| /// <param name="services">A list of services.</param> | ||
| internal void RemoveNotStoppedServices(List<ServiceController> services) | ||
| { | ||
| foreach (ServiceController service in services) | ||
| { | ||
| if (service.Status != ServiceControllerStatus.Stopped && | ||
| service.Status != ServiceControllerStatus.StopPending) | ||
| { | ||
| services.Remove(service); | ||
| } | ||
| } | ||
| // You shall not modify a collection during enumeration. | ||
| services.RemoveAll(service => | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment why we have to use LINQ.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not LINQ. It's a method of
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is just better. Please add a comment. |
||
| service.Status != ServiceControllerStatus.Stopped && | ||
| service.Status != ServiceControllerStatus.StopPending); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the possible impact of changing the method signature here would be, but given it's a private method anyway, it's probably safe to do as long as the code calling the method is still OK to call it with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is only called from one place, hence I believe it's separated to provide better readability.