c# await 关键字错误

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);
}
原文地址:https://www.cnblogs.com/jacle169/p/3205152.html