我写一个文件IsolatedStorageFile与异步调用对WriteAsync的异步调用,我如何知道它什么时候完成?
async void Base64ToImage()
{
byte[] data;
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = isf.OpenFile("image.p64", FileMode.Open, FileAccess.ReadWrite))
{
data = new byte[isfs.Length];
isfs.Read(data, 0, data.Length);
isfs.Close();
}
using (IsolatedStorageFileStream stream = isf.OpenFile("newReConvertedFile.png", FileMode.Create))
{
await stream.WriteAsync(data, 0, data.Length);
///////////////////The problem is here, how would i know when WriteAsync is complete to then fire the reload method?
//reLoadFile();
}
}
}
我需要知道什么时候WriteAsync完成重新加载另一种方法,文件,如何将我去这样做?
编辑:
其实我的第一个想法是将文件保存到isostorage然后孙中山图像URI该文件,但不能设置URI来isostorage为图像或至少我不能去显示
我最初的想法是等待方法调用重新加载文件,但我得到一个错误“???不返回任务,不能等待。考虑改变它返回“,但我不知道如何去做这件事。
这里的想法是将几个图像转换为Base64(SQLite数据库),但只加载所选的,以显示。
的reLoadFile方法如下
async void reLoadFile()
{
byte[] newFile;
using (IsolatedStorageFile newFileLoc = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream newFileStream = newFileLoc.OpenFile("newReConvertedFile.png", FileMode.Open, FileAccess.ReadWrite))
{
newFile = new byte[newFileStream.Length];
newFileStream.Read(newFile, 0, newFile.Length);
newFileStream.Close();
var ms = new MemoryStream(newFile);
var image = new BitmapImage();
image.SetSource(ms);
theImage.Source = image;
}
}
}
我一直在寻找的职位,但我不能罚款的方式来得到它的工作,因为如果我把它马上我得到一个异常。 我需要做的是打开文件将其从base64转换为.png,然后在保存后加载.png文件。 如果有人能帮助我,我将不胜感激。
感谢鲍勃。
我不明白为什么这个问题是下投了反对票。它提供了回答这个问题所需的所有细节。 – vcsjones
你不应该使用异步无效,改变你的方法,以异步任务 –
@vcsjones我也不明白它... –