-1

我正在使用 RenderTargetBitmap 渲染导致内存不足异常的图像。有没有办法捕获该异常,以便我可以安全地退出并告诉用户无法渲染图像......而不是让客户端崩溃?

   (MemoryStream imageStream = doSomething())

public Stream doSomething()
{  return renderTarget.Render(); // This is causing the exception  }
4

1 回答 1

0

这是正确的方法:

int memEstimateInMB = 16;
try
{
    using(var fp = new MemoryFailPoint(memEstimateInMB))
    {
        return renderTarget.Render();
    }
}
catch(InsufficientMemoryException e) // note that this is a different exception than OOM
{
    // your allocation would have failed (probably)
    // handle accordingy
}
于 2013-06-05T16:57:31.833 回答