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

问题描述 投票:1回答:1

这是我的代码示例

  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没有运气。

c# resources device sharpdx
1个回答
0
投票

我有同样的问题,对我有用的是

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

device.Properties.BufferSize = 128;
device.Acquire();
© www.soinside.com 2019 - 2024. All rights reserved.