Skip to content
Permalink
Browse files

GetDecompiledProjectCmdlet: remove unnecessary use of ConcurrentQueue

  • Loading branch information
siegfriedpammer committed Feb 2, 2020
1 parent e0ee8bf commit 350c54d575abce1c92ed1b517a8db3c6bcbc5202
Showing with 15 additions and 12 deletions.
  1. +15 −12 ICSharpCode.Decompiler.PowerShell/GetDecompiledProjectCmdlet.cs
@@ -21,18 +21,19 @@ public class GetDecompiledProjectCmdlet : PSCmdlet, IProgress<DecompilationProgr
[ValidateNotNullOrEmpty]
public string LiteralPath { get; set; }

readonly object syncObject = new object();
int completed;
string fileName;
ConcurrentQueue<ProgressRecord> progress = new ConcurrentQueue<ProgressRecord>();
ProgressRecord progress;

public void Report(DecompilationProgress value)
{
int current = completed;
int next = current + 1;
next = Interlocked.CompareExchange(ref completed, next, current);
progress.Enqueue(new ProgressRecord(1, "Decompiling " + fileName, $"Completed {next} of {value.TotalNumberOfFiles}: {value.Status}") {
PercentComplete = (int)(next * 100.0 / value.TotalNumberOfFiles)
});
lock (syncObject) {
completed++;
progress = new ProgressRecord(1, "Decompiling " + fileName, $"Completed {completed} of {value.TotalNumberOfFiles}: {value.Status}") {
PercentComplete = (int)(completed * 100.0 / value.TotalNumberOfFiles)
};
}
}

protected override void ProcessRecord()
@@ -51,12 +52,14 @@ protected override void ProcessRecord()
Thread.Sleep(timeout);

while (!task.IsCompleted) {
if (progress.TryDequeue(out var record)) {
while (progress.TryDequeue(out var next)) {
record = next;
}
ProgressRecord progress;
lock (syncObject) {
progress = this.progress;
this.progress = null;
}
if (progress != null) {
timeout = 100;
WriteProgress(record);
WriteProgress(progress);
} else {
Thread.Sleep(timeout);
timeout = Math.Min(1000, timeout * 2);

0 comments on commit 350c54d

Please sign in to comment.
You can’t perform that action at this time.