I am trying to save some simple data in my C# Windows 8 application, however, I can’t seem to get any of the async file operations to work.
I can write:
ApplicationData.Current.LocalFolder.CreateFileAsync(...);
however, if I add an await command in front of that and attempt to convert it into the form:
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(...);
I start getting compiler errors. Specifically that that await operator can only be used with async operations. Since the operation is async I’m a bit confused.
What am I doing wrong?
The method in which your async call (in this case
CreateFileAsync) must be markedasyncin order for you to call an async method withawait.See the question here for a properly formed method in which to call an async method with
await.