2014-01-10 51 views
0

我正在开发应用程序,其中我先检查图像是否存在于独立存储中。如果图像不存在,那么我先下载然后将它们存储在独立存储中。但是我得到异常“类型“System.ObjectDisposedException”的异常出现在mscorlib.ni.dll但在用户代码“在using (IsolatedStorageFileStream mystream = istore.CreateFile(item.ImageUrl)).在后台独立存储中存储图像

private void checkimage(Model item) 
    { 
     using (IsolatedStorageFile istore = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 

      if (istore.FileExists(item.ImageUrl)) 
      { 

      } 
      else 
      { 
       BitmapImage imgage = new BitmapImage(new Uri(item.ImageUrl, UriKind.Absolute)); 
       imgage.CreateOptions = BitmapCreateOptions.BackgroundCreation; 
       imgage.ImageOpened += (o, e) => 
        { 
         using (IsolatedStorageFileStream mystream = istore.CreateFile(item.ImageUrl)) 
         { 
          BitmapImage bitmap = new BitmapImage(); 
          bitmap.SetSource(mystream); 
          WriteableBitmap wb = new WriteableBitmap(bitmap); 

          Extensions.SaveJpeg(wb, mystream, wb.PixelWidth, wb.PixelHeight, 0, 85); 
          mystream.Close(); 
         } 

        }; 
       } 
     } 
     } 

回答

1

它看起来像istore已经在当时被破坏,没有处理的时候你想创建文件。尝试在事件主体中再次创建(istore)或使用全局变量并手动处理。

例如:移动BitmapImage imgage...以外的第一个using并再次创建istore。

+0

谢谢。这是你建议的同样的问题 –

+0

这是因为我可以存储在独立存储中的文件的名称非常大。 –