繁体   English   中英

在隔离存储wp7中创建文件

[英]creating a file in isolated storage wp7

我正在使用以下代码在隔离存储中创建文件

mystorage = IsolatedStorageFile.GetUserStoreForApplication();
if (mystorage.FileExists(scanName))
{
    mystorage.DeleteFile(scanName);
}
WriteableBitmap wb = new WriteableBitmap(canImage, null);
using (MemoryStream stream = new MemoryStream())
{
    wb.SaveJpeg(stream, (int)canImage.Width, (int)canImage.Height, 0, 100);
    using (IsolatedStorageFileStream local = new IsolatedStorageFileStream(scanName, FileMode.Create, mystorage))
    {
        local.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length);
    }
}
if (MessageBox.Show("Scan updated successfully") == MessageBoxResult.OK)
{
    App.isTransformRequest = false;
    NavigationService.Navigate(new Uri("/View/EditDocument.xaml?paramList=" + App.currentName, UriKind.RelativeOrAbsolute));
}

此代码可以正常工作。 但是我想检测天气是否完全创建了文件,此后,我只想显示成功消息。 我当前的工作方式是在完全创建文件之前显示成功消息,我希望仅在文件完全创建(即流已完全写入)之后显示该消息。

使用IsolatedStorageFileStream (msdn)BeginWrite方法,您可以在ActionCallback上重新注册以继续使用UI中的重定向选项。

请注意,如果您的回调在UI-Thread中显示MessageBox,则必须使用Dispatcher (msdn)同步ThreadContext。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM