Skip to content

Commit

Permalink
Fix for dispose of ComputeRelativeTimesProgressMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
pescuma committed Apr 30, 2014
1 parent f04943f commit a358397
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions csharp/ProgressMonitor/ProgressMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Compile Include="console\widget\ElapsedWidget.cs" />
<Compile Include="console\widget\TextWidget.cs" />
<Compile Include="devel\ComputeRelativeTimesProgressMonitor.cs" />
<Compile Include="utils\ActionDisposable.cs" />
<Compile Include="utils\FilteredFlatProgressMonitor.cs" />
<Compile Include="utils\FlatToHierarchicalProgressMonitor.cs" />
<Compile Include="console\MachineReadableConsole.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public IDisposable ConfigureSteps(params int[] aSteps)
{
steps = new Step[aSteps.Length == 1 ? aSteps[0] : aSteps.Length];

return next.ConfigureSteps(aSteps);
next.ConfigureSteps(aSteps);

return new ActionDisposable(() =>
{
if (currentStep >= 0 && currentStep < steps.Length)
Finished();
});
}

public void StartStep(string stepName = null)
Expand All @@ -47,6 +53,8 @@ public void Finished()
next.Finished();

DumpTimes();

currentStep++;
}

private void OnFinishedStep()
Expand Down
19 changes: 19 additions & 0 deletions csharp/ProgressMonitor/utils/ActionDisposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace org.pescuma.progressmonitor.utils
{
internal class ActionDisposable : IDisposable
{
private readonly Action dispose;

public ActionDisposable(Action dispose)
{
this.dispose = dispose;
}

public void Dispose()
{
dispose();
}
}
}
15 changes: 0 additions & 15 deletions csharp/ProgressMonitor/utils/FlatToHierarchicalProgressMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,5 @@ public void ReportError(params string[] message)
{
flat.ReportError(message);
}

private class ActionDisposable : IDisposable
{
private readonly Action dispose;

public ActionDisposable(Action dispose)
{
this.dispose = dispose;
}

public void Dispose()
{
dispose();
}
}
}
}

0 comments on commit a358397

Please sign in to comment.