Throw an exception if a reservation is eaten by the GC. Better to die early with a known error than to desync later.

This commit is contained in:
Paul Chote
2011-02-24 17:26:14 +13:00
parent fa6a98cca3
commit 7f39909dc8
2 changed files with 13 additions and 8 deletions

View File

@@ -14,22 +14,27 @@ namespace OpenRA
{
public class DisposableAction : IDisposable
{
public DisposableAction(Action a) { this.a = a; }
public DisposableAction(Action onDispose, Action onFinalize)
{
this.onDispose = onDispose;
this.onFinalize = onFinalize;
}
Action a;
Action onDispose;
Action onFinalize;
bool disposed;
public void Dispose()
{
if (disposed) return;
disposed = true;
a();
onDispose();
GC.SuppressFinalize(this);
}
~DisposableAction()
{
Dispose();
onFinalize();
}
}
}