【问题标题】:getting "The requested resource is in use" when using sharpDX使用sharpDX时得到“请求的资源正在使用中”
【发布时间】:2014-02-22 22:28:40
【问题描述】:

这是我的代码示例

  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】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      相关资源
      最近更新 更多