How to handle not-enough-isolatedstorage issue deep in data loader?
Posted
by Edward Tanguay
on Stack Overflow
See other posts from Stack Overflow
or by Edward Tanguay
Published on 2010-06-13T10:23:46Z
Indexed on
2010/06/13
10:32 UTC
Read the original article
Hit count: 271
Silverlight
|isolatedstorage
I have a silverlight application which loads data from many external data sources into IsolatedStorage, and while loading any of these sources if it does not have enough IsolatedStorage, it ends up in a catch statement. At that point in that catch statement I would like to ask the user to click a button to approve silverlight to increase the IsolatedStorage capacity.
The problem is, although I have a "SwitchPage()" method with which I display a page, if I access it at this point it is too deep in the loading process and the application always goes into an endless loop, hangs and crashes.
I need a way to branch out of the application completely somehow to an independent UserControl which has a button and code behind which does the increase logic.
What is a solution for an application to be able to branch out of a loading process catch statement like this, display a user control which has a button to ask the user to increase the IsolatedStorage?
public static void SaveBitmapImageToIsolatedStorageFile(OpenReadCompletedEventArgs e, string fileName)
{
try
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
{
Int64 imgLen = (Int64)e.Result.Length;
byte[] b = new byte[imgLen];
e.Result.Read(b, 0, b.Length);
isfs.Write(b, 0, b.Length);
isfs.Flush();
isfs.Close();
isf.Dispose();
}
}
}
catch (IsolatedStorageException)
{
//handle: present user with button to increase isolated storage
}
catch (TargetInvocationException)
{
//handle: not saved
}
}
© Stack Overflow or respective owner