This is about ReSharper\'s warning \"Access to disposed closure\" which usually appears when an object which is later disposed is used in a lambda. Access to disposed closur
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.