从 UWP BackgroundTask 调用 MediaCapture.InitializeAsync [英] Call MediaCapture.InitializeAsync from UWP BackgroundTask

查看:22
本文介绍了从 UWP BackgroundTask 调用 MediaCapture.InitializeAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 UWP 应用程序的 BackgroundTask 期间拍照.我在 documentation 中读到 InitializeAsync 应该在 STA 线程上,但是否有某种方法可以从 MTA 实现这一目标?我不知道,例如 Dispatchers 或其他解决方法.

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.

在我的实际场景中,当我在 InitializeAsync 之后调用 CapturePhotoToStreamAsync 时,出现以下异常:

In my actual scenario, when I call CapturePhotoToStreamAsync just after the InitializeAsync, the following exception occurs:

System.Runtime.InteropServices.COMException (0xC00D3E82):一个媒体源不能从停止状态进入暂停状态.

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.

推荐答案

我认为你不会让它在 BackgroundTask 中工作 - 如 MSDN 所说:

I don't think you will get it to work in BackgroundTask - as MSDN says:

InitializeAsync 应从应用的主 UI 线程调用.如需了解详情,请参阅启用敏感设备的指南.

InitializeAsync should be called from the main UI thread of your app. For more information, see Guidelines for enabling sensitive devices.

这篇关于从 UWP BackgroundTask 调用 MediaCapture.InitializeAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆