Chetan Zope
Chetan Zope

Reputation: 55

Storing images in isolated storage in background

I am developing app in which i have check first the images is present in isolated storage.If image is not there then i download first and then store them in isolated storage .But I got exception "An exception of type 'System.ObjectDisposedException' occurred in mscorlib.ni.dll but was not handled in user code " at 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();
                        }

                    };
               }
        }
        }

Upvotes: 0

Views: 62

Answers (1)

crea7or
crea7or

Reputation: 4490

It looks like istore has been destroyed at the time, when you trying to create the file. Try to create (istore) again in the event body or use global variable and handle dispose by hand.

For example: move BitmapImage imgage... outside the first using and create istore again.

Upvotes: 1

Related Questions