简体   繁体   English

不包含“完成” /“然后”的定义

[英]does not contain a definition for 'done'/'then'

While using CreateFileAsync winRT APi i am getting this error; 使用CreateFileAsync winRT APi时出现此错误;

' Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFile> ' does not contain a definition for ' done ' and no extension method ' done ' accepting a first argument of type ' Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFile> ' could be found (are you missing a using directive or an assembly reference) ' Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFile> '不包含' done '的定义,也没有扩展方法' done '接受类型为' Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFile> '的第一个参数可以找到(您是否缺少using指令或程序集引用)

Why? 为什么?

The example from msdn is thesame as well msdn API reference 来自msdn的示例与msdn API参考相同

Lise I said in a comment, the example is in JavaScript, not C#. 我在评论中说,这个例子是用JavaScript编写的,而不是C#。 The proper way to use asynchronous methods from C# is to use await : 从C#使用异步方法的正确方法是使用await

var file = await Windows.Storage.DownloadsFolder.CreateFileAsync("sample.txt");
// Your code

This code must be in a method marked as async . 此代码必须在标记为async的方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM