Do not modify enumerated tree when plot is shown. (#853)

When going to sleep some node are removed on my PC and it crash with
InvalidOperationException because the collection is modified during
enumeration.

 So return a copy of the filtered list instead of yield return.
This commit is contained in:
Nicolas Graziano
2022-11-01 09:49:09 +01:00
committed by GitHub
parent ea87e39188
commit 4efc652ed5
+5 -6
View File
@@ -8,6 +8,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Aga.Controls.Tree;
namespace LibreHardwareMonitor.UI;
@@ -59,12 +60,10 @@ public class TreeModel : ITreeModel
Node node = GetNode(treePath);
if (node != null)
{
foreach (Node n in node.Nodes)
if (_forceVisible || n.IsVisible)
yield return n;
return node.Nodes.Where(n => _forceVisible || n.IsVisible).ToList();
}
else
{ }
return Enumerable.Empty<Node>();
}
public bool IsLeaf(TreePath treePath)
@@ -122,4 +121,4 @@ public class TreeModel : ITreeModel
NodesRemoved?.Invoke(this, args);
}
}
}