public static bool EnsureMemoryAvailability(int expectedSizeMegaBytes)
{
if (expectedSizeMegaBytes < 0)
{
throw new ArgumentException("Param expectedSizeBytes should be positive", "expectedSizeMegaBytes");
}
bool available = true;
MemoryFailPoint p = null;
try
{
p = new MemoryFailPoint(expectedSizeMegaBytes);
}
catch(InsufficientMemoryException)
{
available = false;
}
finally
{
if(p != null)
{
try { p.Dispose(); }
catch(Exception)
{
// ignored
}
}
}
return available;
}