public void ExecuteWithProtection(MemoryProtectionConstraints requestedProtection, Action action) { MemoryProtectionConstraints oldProtection = MemoryProtectionConstraints.None; Helper.ThrowWin32ExceptionIfFalse(() => _protection.VirtualProtect(_address, _length, requestedProtection, out oldProtection)); try { action(); } finally { Helper.ThrowWin32ExceptionIfFalse(() => _protection.VirtualProtect(_address, _length, oldProtection, out oldProtection)); } }