当我这么做时:
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‘等待’操作符只能在异步方法中使用。考虑使用‘异步’修饰符标记此方法,并将其返回类型更改为'Task'.。
所以我试着等待‘异步mc.InitializeAsync();',然后我得到了这个错误:
‘错误1;预期’‘
我做错了什么?也许是图书馆出了问题?谢谢
发布于 2014-12-12 16:39:13
您需要像这样更改您的方法:
public async Task Foo()
{
//code
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
}
}https://stackoverflow.com/questions/27447976
复制相似问题