Browse Source

- Properly reset AnalyzerSearchTreeNode on assembly list changes.

- Add a stopwatch to ThreadingSupport
pull/2606/head
Siegfried Pammer 4 years ago
parent
commit
9d264f56d6
  1. 5
      ILSpy/Analyzers/AnalyzerSearchTreeNode.cs
  2. 15
      ILSpy/TreeNodes/ThreadingSupport.cs

5
ILSpy/Analyzers/AnalyzerSearchTreeNode.cs

@ -42,7 +42,8 @@ namespace ICSharpCode.ILSpy.Analyzers
this.analyzerHeader = analyzerHeader; 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; public override object Icon => Images.Search;
@ -117,6 +118,7 @@ namespace ICSharpCode.ILSpy.Analyzers
this.LazyLoading = true; this.LazyLoading = true;
threading.Cancel(); threading.Cancel();
this.Children.Clear(); this.Children.Clear();
RaisePropertyChanged(nameof(Text));
} }
} }
@ -134,6 +136,7 @@ namespace ICSharpCode.ILSpy.Analyzers
this.LazyLoading = true; this.LazyLoading = true;
threading.Cancel(); threading.Cancel();
this.Children.Clear(); this.Children.Clear();
RaisePropertyChanged(nameof(Text));
} }
return true; return true;
} }

15
ILSpy/TreeNodes/ThreadingSupport.cs

@ -18,6 +18,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -37,18 +38,22 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary> /// </summary>
class ThreadingSupport class ThreadingSupport
{ {
Task<List<SharpTreeNode>> loadChildrenTask; readonly Stopwatch stopwatch = new Stopwatch();
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
Task<List<SharpTreeNode>> loadChildrenTask;
public bool IsRunning { public bool IsRunning {
get { return loadChildrenTask != null && !loadChildrenTask.IsCompleted; } get { return loadChildrenTask != null && !loadChildrenTask.IsCompleted; }
} }
public long EllapsedMilliseconds => stopwatch.ElapsedMilliseconds;
public void Cancel() public void Cancel()
{ {
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
loadChildrenTask = null; loadChildrenTask = null;
cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource = new CancellationTokenSource();
stopwatch.Reset();
} }
/// <summary> /// <summary>
@ -56,6 +61,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary> /// </summary>
public void LoadChildren(SharpTreeNode node, Func<CancellationToken, IEnumerable<SharpTreeNode>> fetchChildren) public void LoadChildren(SharpTreeNode node, Func<CancellationToken, IEnumerable<SharpTreeNode>> fetchChildren)
{ {
stopwatch.Restart();
node.Children.Add(new LoadingTreeNode()); node.Children.Add(new LoadingTreeNode());
CancellationToken ct = cancellationTokenSource.Token; CancellationToken ct = cancellationTokenSource.Token;
@ -89,12 +95,11 @@ namespace ICSharpCode.ILSpy.TreeNodes
delegate { delegate {
if (loadChildrenTask == thisTask) if (loadChildrenTask == thisTask)
{ {
stopwatch.Stop();
node.Children.RemoveAt(node.Children.Count - 1); // remove 'Loading...' node.Children.RemoveAt(node.Children.Count - 1); // remove 'Loading...'
node.RaisePropertyChanged(nameof(node.Text)); node.RaisePropertyChanged(nameof(node.Text));
}
if (continuation.Exception != null) if (continuation.Exception != null)
{ // observe exception even when task isn't current
if (loadChildrenTask == thisTask)
{ {
foreach (Exception ex in continuation.Exception.InnerExceptions) foreach (Exception ex in continuation.Exception.InnerExceptions)
{ {

Loading…
Cancel
Save