When using the UWP MIDI API with a physical MIDI device, the app hangs on exit and cannot be forcefully terminated neither from command line nor from the Task Manager.
This happens for all UWP apps that use MIDI, including the official example from MSDN, without modifications.
I have raised an issue on GitHub about this, but it does not seem to be a new problem. MIDI is supposedly broken since 2014.
Is there a way to circumvent this problem in UWP through other means? I'm writing in C#, but I am fluent in C++ and could use lower-level APIs, if they existed. I only need to get MIDI input from a selected MIDI device (keyboard).
I also tried using the winmm.dll
as suggested in the related post (Getting signals from a MIDI port in C#), but this does not work for me. The midiInGetNumDevs()
method returns 0 when used from a UWP app.
I am using M-Audio Fast Track USB sound card (connected via USB) and an M-Audio 88es Keystation MIDI Keyboard (connected via USB). I haven't had problems in desktop applications.
I have discovered a partial workaround where I move the deallocation code to the App Suspending
event handler instead of having it in a destructor. However, the problem still arises when a device is unplugged during app's lifetime. If the MIDI device is plugged in while the app is running, the app closes without problems (with the workaround). If the MIDI device is plugged in before the app is run and remains plugged in while the app is running, the app closes without problems (with the workaround). Only if the device is plugged out while the app is running will the app hang on close, regardless of whether the deallocation code is done in the destructor or in the App Suspending
handler.