警告 C4451:使用 ref 类 BackgroundTaskDeferral 会导致无效的封送处理 [英] Warning C4451: Usage of ref class BackgroundTaskDeferral can lead to invalid marshaling
问题描述
关于我的通用应用项目,我收到编译警告:
Regarding my universal app project, I am getting compilation warning:
警告 C4451:BackgroundServerTasks::ServerTask::Run::::deferral":在此上下文中使用引用类Windows::ApplicationModel::Background::BackgroundTaskDeferral"会导致对象的无效封送跨上下文
注意:考虑改用Platform::Agile"
在这个文件.我该如何解决此警告?显然,这是由于我在 create_task
中使用了 BackgroundTaskDeferral
.除了 这篇文章 解决了这个问题,但我不确定它是否适用于这种情况.
in this file. How could I resolve this warning? Apparently, it is due to my using the BackgroundTaskDeferral
within a create_task
. I found no solution on Bing except for this post which dismisses the problem but I am not sure if it is applicable in this case.
推荐答案
让我惊讶的是 Windows::ApplicationModel::Background::BackgroundTaskDeferral
并不敏捷.
It surprises me that Windows::ApplicationModel::Background::BackgroundTaskDeferral
is not agile.
尝试在相同的上下文中完成延期,即:
Try completing the deferral in the same context, i.e.:
create_task(writer->StoreAsync()).then([this, deferral](unsigned int n)
{
deferral->Complete();
}, task_continuation_context::use_current());
另一种选择是使用 Platform::Agile<>
包装器:
Another option is to use a Platform::Agile<>
wrapper:
Platform::Agile<Windows::ApplicationModel::Background::BackgroundTaskDeferral> Deferral;
// ...
Deferral = taskInstance->GetDeferral();
这篇关于警告 C4451:使用 ref 类 BackgroundTaskDeferral 会导致无效的封送处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!