Skip to content

Commit 64c2f4f

Browse files
Apply suggestions from code review and add documentation
1 parent c545c08 commit 64c2f4f

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/BenchmarkDotNet/Helpers/DisposeAtProcessTermination.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
using System;
2+
using System.Runtime.InteropServices;
23

34
namespace BenchmarkDotNet.Helpers
45
{
56
/// <summary>
6-
/// Ensures that Dispose is called at termination of the Process.
7+
/// Ensures that explicit Dispose is called at termination of the Process.
78
/// </summary>
8-
public class DisposeAtProcessTermination : IDisposable
9+
/// <remarks>
10+
/// <para>
11+
/// This class exists to help in reverting system state where C#'s using statement does not
12+
/// suffice. I.e. when Benchmark's process is aborted via Ctrl-C, Ctrl-Break or via click on the
13+
/// X in the upper right of Window.
14+
/// </para>
15+
/// <para>
16+
/// Usage: Derive your clas that changes system state of this class. Revert system state in
17+
/// override of <see cref="Dispose"/> implementation.
18+
/// Use your class in C#'s using statement, to ensure system state is reverted in normal situations.
19+
/// This class ensures your override is also called at process 'abort'.
20+
/// </para>
21+
/// <para>
22+
/// Note: This class is explicitly not responsible for cleanup of Native resources. Of course,
23+
/// derived classes can cleanup their Native resources (usually managed via
24+
/// <see cref="SafeHandle"/> derived classes), by delegating explicit Disposal to their
25+
/// <see cref="IDisposable"/> fields.
26+
/// </para>
27+
/// </remarks>
28+
public abstract class DisposeAtProcessTermination : IDisposable
929
{
1030
public DisposeAtProcessTermination()
1131
{
1232
Console.CancelKeyPress += OnCancelKeyPress;
1333
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
14-
// It does not make sense to include a finalizer. As we are subscribed to static events,
15-
// it will never be called.
34+
// It does not make sense to include a Finalizer. We do not manage any native resource and:
35+
// as we are subscribed to static events, it would never be called.
1636
}
1737

1838
/// <summary>

0 commit comments

Comments
 (0)