Is there any way to get list of files/directories synchronously with c++ or c# in Windows Store Apps/windows phone apps? All examples are asynchronously..
-
2Why do you want it to be synchronously? Any delay under 50 ms will cause the app to fail certification AFAIK. – Iris Classon Dec 06 '14 at 18:46
-
Delay over rather than under I guess you mean – David Heffernan Dec 06 '14 at 19:53
-
OPS, my bad! Yes - OVER :) – Iris Classon Dec 07 '14 at 17:51
1 Answers
In most cases you'll want to do this asynchronously. Users don't like it when the app UI hangs, and the await system tries to make asynchronous programming as smooth as possible so you don't have to implement significant amounts of custom code to keep the app responsive.
That said, for cases which aren't likely to have a significant impact on responsiveness you can go synchronous:
If the files are in the install or application data folders then the app can access them with standard C++ file API. The app won't have permissions for files elsewhere to do this and will need to use the asynchronous StorageItem API (StorageFolders and StorageFiles)
If the app is calling the StorageItem from a background thread then it can synchronously wait for the async option to complete. The app cannot block the UI thread this way though: Task.Wait will fail in the UI thread.
var thread = myFolder.GetFilesAsync().AsTask();
thread.Wait();

- 21,714
- 3
- 32
- 54