4
我有这段代码GetFilesAsync停止工作
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应用程序调用它;
this.IconExists = this.Game != null && Storage.Exists(this.IconName).Result;
所以,如果我把一个破发点以上线并运行它一步一步来,它的工作原理,但没有突破,只是运行该应用程序会导致应用程序挂起。
一个类似的代码正在工作在几天前的提交;
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; } }
}
}
任何想法?
感谢分享的是,它一定会帮助有同样的问题等。 –