问题
I am trying to take a photo during a BackgroundTask at an UWP application. I read at documentation that InitializeAsync should be on the STA thread but is there some approach to achieve that from a MTA? I don't known, something like Dispatchers or others workarounds.
In my actual scenario, when I call CapturePhotoToStreamAsync just after the InitializeAsync, the following exception occurs:
System.Runtime.InteropServices.COMException (0xC00D3E82): A media source cannot go from the stopped state to the paused state.
The funny thing is that it works if my app is not suspended.
回答1:
I don't think you will get it to work in BackgroundTask - as MSDN says:
InitializeAsync should be called from the main UI thread of your app. For more information, see Guidelines for enabling sensitive devices.
来源:https://stackoverflow.com/questions/35119740/call-mediacapture-initializeasync-from-uwp-backgroundtask