我有一个用于 Windows Store 应用程序(又名 Metro)的简单实用程序集合,但我发现它ApplicationData.Current.LocalFolder.GetFileAsync
在连续调用时似乎挂起(即,一旦我尝试调试它并逐步执行,问题就消失了) .
public static async Task<LocalCache<T>> LoadCache()
{
try
{
// Get the input stream for the cache
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(GetFileNameForType());
using (IInputStream inStream = await file.OpenSequentialReadAsync())
{
// Deserialize the cache
DataContractSerializer serializer = new DataContractSerializer(typeof(LocalCache<T>));
return (LocalCache<T>)serializer.ReadObject(inStream.AsStreamForRead());
}
}
catch (FileNotFoundException)
{
return new LocalCache<T>();
}
}
似乎没有任何过载来指定打开文件的模式,而且它似乎没有返回,这让我有点难过。我能做些什么来防止这种僵局?