Access to disposed closure - mark methods as safe

柔情痞子 提交于 2019-11-30 11:28:52

You can use ReSharper's annotations to fix this. ReSharper has no way of knowing how long the closure will last, e.g. it might be assigned to a field, and so it warns you that you might possibly be using something that will be disposed by the time the lambda is called.

You can fix it like this:

void DoThisTwice([InstantHandle] Action action)
{
    action();
    action();
}

The InstantHandle attribute tells ReSharper that the action is called immediately and not stored beyond the scope of the method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!