使用sharpDX时获取“请求的资源正在使用中”

时间:2014-02-22 22:28:41

标签: c# resources device sharpdx

这是我的代码示例

  directInput = new DirectInput();// Initialize DirectInput
            deviceGuid = Guid.Empty;// Find a Joystick Guid

            foreach (DeviceInstance deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices))
            { deviceGuid = deviceInstance.InstanceGuid; }


            directInput = new DirectInput();
            device = new Joystick(directInput, deviceGuid);
            device.Acquire();
            device.Properties.BufferSize = 128;
            while (true)
            {
                device.Poll();
                var data = device.GetBufferedData();
                foreach (var state in data)
                {
                    if (state.Offset == JoystickOffset.X)
                    {
                        MessageBox.Show( state.Value.ToString() );
                    }
                }
            }

此示例应该让我更改状态,但在设置缓冲区大小时,我得到“请求的资源正在使用中”。通过使用deviceState.Buttons [],我可以使用sharpDX代码获取没有问题的按钮状态。效果很好,但GetBufferedData没有运气。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,对我有用的是

device.Acquire();
device.Properties.BufferSize = 128;

device.Properties.BufferSize = 128;
device.Acquire();