Skip to main content

Posts

WP7Contrib: Isolated Storage Cache Provider

15/04/2001 - The code for this example has been updated - new WP7 build of SilverlightSerializer, this has removed the explicit implementation of ISerializeObject interface from the example model classes. WP7Contrib received it's first question on the discussions forum, it was about how to use the  IsolatedStorageCacheProvider . Rich & I have been using this for a while in development and the question highlighted the lack of examples on how to use some of the stuff we've pushed out. So I thought I would share some insight into the demo I produced to answer the question. You'll find the demo in the 'CacheProviderDemo' in the 'Spikes' directory in the  code-base . It demostrates how to add both value & reference types to the cache, how these gets persisted to isolated storage and how values are purged from the cache. Before I show some code snippets I'll give some background to our thinking about caching. As wikipedia states 'a cache...

WP7: Thinking about performance implicitly

It's inevitable as the moon going around the earth - the performance of your Windows Phone 7 app will become an issue during your application development life cycle, hopefully you're using agile practices and therefore this won't happen to late in the process. There is one technique I believe you should always apply to the process and that is ' thinking about performance implicitly '. So I have 3 tips which help me achieve thinking about performance implicitly. The emulator is not your friend - You should as others have pointed out always be testing on a device and not the emulator - the emulator is great for spiking and unit testing but not as environment for building an application, it runs at the speed of the host and I haven't yet managed to find a WP7 phone to match the perf of my 4 * Quad Core machine :) Get the worst device possible -  Okay any device running WP7 will have been certified by MS as acceptable, but there are still great differen...

WP7Contrib: Location Push Model

Anyone who's tried to get your current location of a WP7 device will know this is not as simple as it first appears, the problems really revolve around the frequency at which the location information can be generated by the device (GeoCoordinateWatcher class) and the fact it is generated on the UI thread. Jaime Rodriguez has a very insightful post on the issues, you should read this first if you're not familiar with the issues. For the WP7Contrib we wanted to abstract away the issues and simplify the interface for any developer wanting to get location information. Following the pattern we used for Network Connectivity we use a push model using the MS Reactive Extensions for .Net. We use an observable sequence which returns the current location (latitude & longitude) in one of three ways - the current location, the location by time threshold (seconds or TimeSpan) and the location by distance threshold (metre). The interface for the location service is shown below: pub...

WP7: Know your data

If you've been developing Windows Phone 7 apps you'll be aware of the '90 MB' memory limit guideline detailed in the application certification requirements , if not it says: 5.2.5 Memory Consumption An application must not exceed 90 MB of RAM usage, except on devices that have more than 256 MB of memory. You can use the DeviceExtendedProperties class to query the amount of memory that is available on the device and modify the application behavior at runtime to take advantage of additional memory. For more information, see the DeviceExtendedProperties class in MSDN . I've heard of apps exceeding this limit and still being approved for the app store, but that is not the point of this post , the point is as a developer working on a device you should have a cursory knowledge of the size of your data. The reason is simple because when you exceed the 90 Mb limit (and in all probability you will) you'll be able to identify where your memory problems are quicker an...

WP7Contrib: Thread safe ObservableCollection<T>

Continuing with the introduction of WP7Contrib concepts, patterns & services from my previous post I thought I would explain why we have chosen to implement our own ObservableCollection. As with the desktop version of Silverlight the idea of a 'blocking call' on the UI thread is discouraged, to point where if you do block the UI thread on a WP7 device your application could be automatically torn down - bad user experience. So to get round the issue the Silverlight framework makes use of the standard .Net 'async pattern' - IAsyncResult interface. Examples of this are the HttpWebRequest class and it's counterpart HttpWebResponse , they allow you to execute web requests without blocking the UI thread. The problem with the ObservableCollection<T> supplied by the framework is it's not thread safe for any methods. For example, when you have a control bound to the collection and it's enumerating over the collection and another thread modifies the coll...

WP7Contrib: Network Connectivity Push Model

To start my WP7Contrib blogging contribution I thought I started with something small, easy and relatively quick to explain. If you're familiar with the platform you can get the current network type using the API - NetworkInterface.NetworkInterfaceType . This is a simple synchronous call which returns what MSDN describes as 'the type of the network servicing Internet requests. This is a prime example of a 'pull model' to obtain data. We've turned this model on its head, and produced a 'push model' using the MS Reactive Extensions for .Net . What we did was use an observable sequence which returns values at a specified frequency using the interval method. this.networkObserver = Observable.Interval(TimeSpan.FromMilliseconds(frequency)) .Select(DetermineCurrentStatus) .Subscribe(this.statusSubject); So for every interval we execute the Select and the returned value from DetermineCurrentStatus is pushed to the statusSubject. This is a behavior subj...

WP7Contrib...

Just wanted to announce the go live of WP7Contrib - a community effort based around the MS Window Phone 7 Platform. Rich Griffin and I have spent the last couple of months bring together code snippets and patterns into a cohensive contribution library, we're currently developing an app using the framework and will be giving more details and examples over the next couple of weeks.