Search code examples
uwpmicrophone

Windows 10 UWP on Desktop Access to Microphone Lost When App Loses Focus


I've written a Windows 10 UWP in Visual Studio 2015 in C# that uses speech recognition to perform certain commands. All works great until the PC recovers from a display sleep or the app loses focus/is minimised. After that the app doesn't respond to the microphone unless i restart the app again. The app is designed only to be used on a couple of my Windows 10 Desktop PCs, so not concerned about mobile or other platform functionality. Is there any way of ensuring the app remains "connected" to the microphone or have I gone down a "blind alley" with UWP and should I have built it in WPF? I had assumed UWP was the future standard that MS was touting and that new apps should only be written in this format and not Forms, WCF or WPF. Am I wrong and is there still a future for WPF (if "yes" can I convert my UWP app to WPF in the hope that I can still have full access to thing like the microphone as I did in an older vb.net forms version of my app?).

So, to clarify, I need to know the following:

  1. Can a Windows 10 UWP app on Windows 10 Desktop keep connected to a microphone even if app minimised/screen timeout?
  2. If the answer is No, then will WPF be the best route and is support for that format/platform likely to continue to be pushed as much as UWP?
  3. If I have to go down the route of WPF can my UWP app be converted to WPF?
  4. If A Win Forms app is the only way to ensure constant access to microphone how long is support for win forms going to continue as it is not recommended to write new apps in this format?

Any help would be very much appreciated, as I've spent a lot of time re-writing my old vb.net win forms app as a C# UWP app. Thanks, Richie


Solution

  • When a UWP app is minimised, it's suspend. There is no way to keep connected to a microphone. For more info, you can check Windows 10 universal Windows platform (UWP) app lifecycle.

    Since you only need the app to work on Windows 10 Desktop PCs, then one of the best options would be using WPF, WPF can also work on Windows 10 and would continue to be supported. For example, they've added per-monitor DPI-awareness support for WPF (see https://github.com/Microsoft/WPF-Samples/tree/master/PerMonitorDPI). And a lot of UWP APIs can be used in WPF, you should be able to convert your UWP app to WPF manually. For more information, see this answer.