?
Solved

Get the amount of available memory in Silverlight

Posted on 2009-04-27
6
Medium Priority
?
971 Views
Last Modified: 2013-11-12
Hello,

In a Silverlight 2 application, how can I know the amount of free memory on the client where I'm running?
0
Comment
Question by:aweilee
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:TSmooth
ID: 24241128
With silverlight, the only available memory you have to work with is IsolatedStorage. IsolatedStorage is per machine and per website but can also be shared amongst web applications hosted on the same domain. The default silverlight settings give you 1MB of storage I believe but you can prompt the user to increase that using the "IsolatedStorage.IncreaseQuotaTo()" method (Note: You cannot increase it yourself programatically, the user must allow you to do so.). To see how much space is available and increase it if necessary, you would use code like the following (http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.increasequotato(VS.95).aspx) :
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            // Request 5MB more space in bytes.
            Int64 spaceToAdd = 5242880;
            Int64 curAvail = store.AvailableFreeSpace;
 
            // If available space is less than
            // what is requested, try to increase.
            if (curAvail < spaceToAdd)
            {
 
                // Request more quota space.
                if (!store.IncreaseQuotaTo(store.Quota + spaceToAdd))
                {
                    // The user clicked NO to the
                    // host's prompt to approve the quota increase.
                }
                else
                {
                    // The user clicked YES to the
                    // host's prompt to approve the quota increase.
                }
            }
        }

Open in new window

0
 
LVL 1

Author Comment

by:aweilee
ID: 24241762
@TSmooth: I'm talking about available RAM. I want to cache items from the server for a smoother application, but caching is only interesting if there is RAM available. Otherwise, I prefer to stream the items directly from the server.
0
 
LVL 16

Expert Comment

by:TSmooth
ID: 24242040
I don't think there is any way to obtain how much RAM is available from within silverlight. However, caching to isolated storage as I mentioned would still give you the same effect, essentially. You would cut down on any latency of sending data across the network and that data would be read from the users local disk cache.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Author Comment

by:aweilee
ID: 24242263
@TSmooth: caching to the Isolated Storage could be a solution, but your code sample implies that the user gets a pop-up about whether she wants to add isolated storage. This cannot be accepted since we want to be able to know whether or not to cache without bothering the user. Of course, we could request a huge isolated storage space, but what about users with small disk sizes? All in all, we need to detect whether or not the users' machine can cope with caching. And all this without bothering the user.
0
 
LVL 16

Accepted Solution

by:
TSmooth earned 2000 total points
ID: 24242679
The default size limit is 1MB. If you need more than that, you could make a one time request to increase that limit to 10mb or whatever, the first time the user launches your application from their machine. Your application would prompt the user stating that if they would like increased performance, they need to opt in to the increased storage.

Your application would then be setup to first check isolated storage for the data and if it wasn't found there, grab it from the server. That way it works whether or not they opt in to the increased storage. Of course.. you can just do all in-memory caching like you mentioned before, but there is no way to see how much ram is available to the best of my knowledge. You'd be relying on the Operating systems caching to hard disk if it runs out of ram.  The nice thing about the isolated storage is that it could be stored there in between client sessions so that if they start the application up the next day, all of the data would be there and you'd only need to pull that data if it's been updated.
0
 
LVL 1

Author Closing Comment

by:aweilee
ID: 31575011
Thanks, it answers my problem thought it isn't exactly the expected answer.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question