从 UWP BackgroundTask 调用 MediaCapture.InitializeAsync

编程入门 行业动态 更新时间:2024-10-26 10:33:25
本文介绍了从 UWP BackgroundTask 调用 MediaCapture.InitializeAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 09:18:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1171515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:BackgroundTask   UWP   InitializeAsync   MediaCapture

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!