GetFilesAsync停止工作
it1352
帮助1人
问题说明
我有这段代码
public static class Storage
{
public async static Task<bool> Exists(string filename)
{
var folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
var _files= await folder.GetFilesAsync(CommonFileQuery.OrderByName).AsTask().ConfigureAwait(false);
var file = _files.FirstOrDefault(x => x.Name == filename);
return file != null;
}
}
和从我的Windows 8 Store应用程序调用它;
and calling it from my Windows 8 Store application;
this.IconExists = this.Game != null && Storage.Exists(this.IconName).Result;
所以,如果我把一个破发点以上线并运行它一步一步来,它的工作原理, 。但没有打破,只是运行的应用程序导致挂起的应用程序
So if I put a break point on the above line and run it step by step, it works, but without breaking and just running the application causes a hang in application.
和类似的代码正在对前几天的承诺;
And a similar code was working on a few days ago's commit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.Storage;
using Windows.Storage.Search;
namespace eggrr.Core.FileStorage
{
public class Storage
{
private IReadOnlyList<StorageFile> _files;
public Storage()
{
_files = GetFilesAsync("Assets").Result;
}
private async Task<IReadOnlyList<StorageFile>> GetFilesAsync(string relativeFolderPath)
{
var path = string.Format("{0}\\{1}", Package.Current.InstalledLocation.Path, relativeFolderPath);
var folder = await StorageFolder.GetFolderFromPathAsync(path);
return await folder.GetFilesAsync(CommonFileQuery.OrderByName).AsTask().ConfigureAwait(false);
}
public bool Exists(string filename)
{
var file = _files.FirstOrDefault(x => x.Name == filename);
return file != null;
}
private static readonly Storage _instance = new Storage();
public static Storage Instance { get { return _instance; } }
}
}
任何想法?
Any ideas?
正确答案
#1
看来这个解决它的问题;
Seems this solved it issue;
public static class Storage
{
private static IReadOnlyList<StorageFile> _files;
static Storage()
{
_files = GetFilesAsync("Assets").Result;
}
private async static Task<IReadOnlyList<StorageFile>> GetFilesAsync(string relativeFolderPath)
{
var folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets").AsTask().ConfigureAwait(false);
return await folder.GetFilesAsync(CommonFileQuery.OrderByName).AsTask().ConfigureAwait(false);
}
public static bool Exists(string filename)
{
var file = _files.FirstOrDefault(x => x.Name == filename);
return file != null;
}
}
这更多信息;
- WinRT: Loading static data with GetFileFromApplicationUriAsync()
- http://nitoprograms.blogspot.com/2012/07/dont-block-on-async-code.html
- http://lunarfrog.com/blog/2012/01/23/simplicity-of-async-and-await/
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcffiff
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22