アプリケーション パッケージにファイルが存在するかどうかを確認するルーチンを作成しようとしています。この件についてたくさん読んだ後、MSがFileExists関数をAPIに入れるのを忘れていたことは明らかですが(意図的かどうかにかかわらず)、これが私が今のところどこにいるのかです...
public async Task<bool> CheckFile(string filePath)
{
bool found = false;
try
{
Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
Windows.Storage.StorageFolder installedLocation = package.InstalledLocation;
StorageFile file = await installedLocation.GetFileAsync("Assets\\" + filePath);
found = true;
}
catch (System.IO.FileNotFoundException ex)
{
found = false;
}
return found;
}
そして、次から呼び出されます:
private ImageSource _image = null;
private String _imagePath = null;
public ImageSource Image
{
get
{
if (this._image == null && this._imagePath != null)
{
Task<bool> fileExists = CheckFile(this._imagePath);
bool filefound = fileExists.Result;
string realPath = string.Empty;
if (filefound)
{
Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
Windows.Storage.StorageFolder installedLocation = package.InstalledLocation;
realPath = installedLocation + "Assets\\" + this._imagePath;
}
else
{
realPath = "http://<<my url>>/images/" + this._imagePath;
}
this._image = new BitmapImage(new Uri(realPath));
}
return this._image;
}
set
{
this._imagePath = null;
this.SetProperty(ref this._image, value);
}
}
基本的に、画像がローカルに存在するかどうかを確認し、存在しない場合は私のウェブサイトから取得します。
最初の画像ではすべて正常に動作しているように見えますが、「return this._image;」になると、2番目の画像では、すべてがフリーズします...
ここで何が起こっているのか本当にわかりません..
何か助けはありますか?
乾杯ディーン