Search code examples
c#uwpwindows-runtimehid

Share HidDevice with multiple applications


When I create new device using api var device = await HidDevice.FromIdAsync(deviceId, FileAccessMode.ReadWrite); no other application can connect to this hid device until it is disposed. Passing FileAccessMode.Read does not help (other than throwing exceptions when I try to write to device).

This can be easly tested using code:

var device = await HidDevice.FromIdAsync(deviceId, FileAccessMode.ReadWrite);
var device2 = await HidDevice.FromIdAsync(deviceId, FileAccessMode.ReadWrite);

Device 2 will be null, because it has been already locked by the system.

Is there way to share HidDevice between multiple apps?


Solution

  • Use HidDevice.FromIdAsync(String, FileAccessMode) with FileAccessMode.Read.

    Documentation states, that device will be readonly, but device can still be written into, and can be shared with other apps.