I want to get a folder in my constructor. So, I need a non-async method.
public static Windows.Storage.StorageFolder getStorageImagesDir()
{
Windows.Storage.StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("images", CreationCollisionOption.OpenIfExists).GetResults();
return folder;
}
However, System.InvalidOperationException was thrown, if the folder doesn’t exist for the first time. (Somehow the folder is still created, even the exception is thrown)
When folder is already exist, the function works fine.
May I know anything wrong with my code?
In Desktop .NET, Java, Python, … we can perform folder creation, withn a simple single line of API call. For instance, Directory.CreateDirectory in .NET, File.mkdirs in Java, … So, why in Windows Store App, we need to do it in async way? Doesn’t it make simple thing unnecessary complicated?
Get the code from someone in MSDN.