當有在不同的線程多次調用Windows.Storage.StorageFolder.GetFolderFromPathAsync我得到ArgumentExceptions時。下面是再現問題的測試:的ArgumentException調用StorageFolder.GetFolderFromPathAsync同時
[TestMethod]
public async Task ConcurrentGetFolderFromPath()
{
List<Task> tasks = new List<Task>();
for (int i = 0; i < 10; i++)
{
var task = Task.Run(async() =>
{
string localFolderPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
//await Task.Yield();
var folder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(localFolderPath);
});
tasks.Add(task);
}
await Task.WhenAll(tasks);
}
這裏的例外,我得到:
System.ArgumentException: Value does not fall within the expected range.
Result StackTrace:
at Windows.Storage.StorageFolder.GetFolderFromPathAsync(String path)
at PCLStorage.Test.FolderTests.<<ConcurrentGetFolderFromPath>b__53>d__55.MoveNext() in c:\git\pclstorage\test\PCLStorage.Test\FolderTests.cs:line 205
測試始終失敗對我來說,當我通過自身運行它,但一般經過,當我一起運行與其餘的PCL Storage測試。
我在這裏做錯了什麼? GetFolderFromPathAsync或我使用的任何其他API只能從UI線程使用嗎?或者這可能是WinRT存儲API中的一個錯誤?