我的代码有什么问题?无法将类型IAsyncOperation <StorageFile>隐式转换为StorageFile
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker FilePicker = new FileOpenPicker();
FilePicker.FileTypeFilter.Add(".exe");
FilePicker.ViewMode = PickerViewMode.List;
FilePicker.SuggestedStartLocation = PickerLocationId.Desktop;
// IF I PUT AWAIT HERE V I GET ANOTHER ERROR¹
StorageFile file = FilePicker.PickSingleFileAsync();
if (file != null)
{
AppPath.Text = file.Name;
}
else
{
AppPath.Text = "";
}
}
它给我这个错误:
Cannot implicitly convert type 'Windows.Foundation.IAsyncOperation' to 'Windows.Storage.StorageFile'
如果我加入 '等待',就像评论的代码,我收到以下错误:
¹ 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'.
代码源here
现在我明白了,非常感谢!我开始学习C#,而这个异步/等待的东西对我来说真的很新鲜。 您的帮助非常感谢! – gabrieljcs 2013-05-12 22:16:58