c# await 关键字错误

家住魔仙堡 提交于 2020-01-09 19:41:13

private void OnUnlockCommand(object parameter)
{
   StorageFile file = await Windows.Storage.ApplicationData.
   Current.TemporaryFolder.CreateFileAsync("filename", CreationCollisionOption.ReplaceExisting);
}

The code above will fail with the error message:

Error    2    The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.

To solve this you must add async to the method declaration like below:
private async void OnUnlockCommand(object parameter) {   StorageFile file = await Windows.Storage.ApplicationData.   Current.TemporaryFolder.CreateFileAsync("filename", CreationCollisionOption.ReplaceExisting); }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!