Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

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.

{
foreach (ServiceController service in dependentServices)
{
if (service.Status != ServiceControllerStatus.Stopped)
{
return false;
}
}

return true;
return Array.TrueForAll(dependentServices, service => service.Status == ServiceControllerStatus.Stopped);
}

/// <summary>
Expand All @@ -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 =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment why we have to use LINQ.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not LINQ. It's a method of List<T>.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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>
Expand Down