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);
}
posted @ 2013-07-22 13:29  黎东海  阅读(812)  评论(0编辑  收藏  举报