using System;
namespace ICD.Common.Utils
{
public sealed partial class SafeCriticalSection
{
///
/// Enters the critical section, executes the callback and leaves the section.
///
///
public void Execute(Action callback)
{
if (callback == null)
throw new ArgumentNullException("callback");
try
{
Enter();
callback();
}
finally
{
Leave();
}
}
///
/// Enters the critical section, executes the callback and leaves the section.
///
///
///
///
public T Execute(Func callback)
{
if (callback == null)
throw new ArgumentNullException("callback");
try
{
Enter();
return callback();
}
finally
{
Leave();
}
}
}
}