From 9d264f56d68d4225cdf4210298b535f88bca5515 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 1 Jan 2022 16:54:12 +0100 Subject: [PATCH] - Properly reset AnalyzerSearchTreeNode on assembly list changes. - Add a stopwatch to ThreadingSupport --- ILSpy/Analyzers/AnalyzerSearchTreeNode.cs | 5 ++++- ILSpy/TreeNodes/ThreadingSupport.cs | 15 ++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs index 72cee784e..45fccee57 100644 --- a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs +++ b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs @@ -42,7 +42,8 @@ namespace ICSharpCode.ILSpy.Analyzers this.analyzerHeader = analyzerHeader; } - public override object Text => analyzerHeader + (Children.Count > 0 ? " (" + Children.Count + ")" : ""); + public override object Text => analyzerHeader + + (Children.Count > 0 && !threading.IsRunning ? " (" + Children.Count + ") in " + threading.EllapsedMilliseconds + "ms" : ""); public override object Icon => Images.Search; @@ -117,6 +118,7 @@ namespace ICSharpCode.ILSpy.Analyzers this.LazyLoading = true; threading.Cancel(); this.Children.Clear(); + RaisePropertyChanged(nameof(Text)); } } @@ -134,6 +136,7 @@ namespace ICSharpCode.ILSpy.Analyzers this.LazyLoading = true; threading.Cancel(); this.Children.Clear(); + RaisePropertyChanged(nameof(Text)); } return true; } diff --git a/ILSpy/TreeNodes/ThreadingSupport.cs b/ILSpy/TreeNodes/ThreadingSupport.cs index 13487ad7f..0e5fbf4e0 100644 --- a/ILSpy/TreeNodes/ThreadingSupport.cs +++ b/ILSpy/TreeNodes/ThreadingSupport.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; @@ -37,18 +38,22 @@ namespace ICSharpCode.ILSpy.TreeNodes /// class ThreadingSupport { - Task> loadChildrenTask; + readonly Stopwatch stopwatch = new Stopwatch(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + Task> loadChildrenTask; public bool IsRunning { get { return loadChildrenTask != null && !loadChildrenTask.IsCompleted; } } + public long EllapsedMilliseconds => stopwatch.ElapsedMilliseconds; + public void Cancel() { cancellationTokenSource.Cancel(); loadChildrenTask = null; cancellationTokenSource = new CancellationTokenSource(); + stopwatch.Reset(); } /// @@ -56,6 +61,7 @@ namespace ICSharpCode.ILSpy.TreeNodes /// public void LoadChildren(SharpTreeNode node, Func> fetchChildren) { + stopwatch.Restart(); node.Children.Add(new LoadingTreeNode()); CancellationToken ct = cancellationTokenSource.Token; @@ -89,12 +95,11 @@ namespace ICSharpCode.ILSpy.TreeNodes delegate { if (loadChildrenTask == thisTask) { + stopwatch.Stop(); node.Children.RemoveAt(node.Children.Count - 1); // remove 'Loading...' node.RaisePropertyChanged(nameof(node.Text)); - } - if (continuation.Exception != null) - { // observe exception even when task isn't current - if (loadChildrenTask == thisTask) + + if (continuation.Exception != null) { foreach (Exception ex in continuation.Exception.InnerExceptions) {