【发布时间】:2014-12-12 16:31:44
【问题描述】:
当我这样做时:
try
{
MediaCapture mc = new MediaCapture();
await mc.InitializeAsync();
if (mc.VideoDeviceController.TorchControl.Supported == true)
{
mc.VideoDeviceController.TorchControl.Enabled = true;
if (mc.VideoDeviceController.TorchControl.PowerSupported == true)
{
mc.VideoDeviceController.TorchControl.PowerPercent = 100;
}
}
}
catch(Exception ex)
{
//TODO: Report exception to user
}
我收到了这个错误:
错误 1 'await' 运算符只能在异步方法中使用。考虑使用“async”修饰符标记此方法并将其返回类型更改为“Task”。
所以我尝试'await async mc.InitializeAsync();',然后我得到了这个错误:
'错误1;预计'
我做错了什么?也许图书馆有问题?谢谢
【问题讨论】:
-
您需要学习 C# 中
async关键字的基础知识。 -
是我想要做的。我还没有使用它。
-
您需要将
async关键字添加到您的方法声明中(您已从问题中的代码中省略)并查看 async/await 的文档。如果您对错误消息感到困惑,您稍后可能会陷入混乱。 -
感谢丹尼尔·凯利。你回答了我的问题......我也应该使用异步方法:)。谢谢
标签: c# windows-phone-8 async-await flashlight