WP7 Storing Colours

I just got bitten on the bum by a poor design choice (although I didn’t know it at the time) in the Bin Day application. The app lets a user pick a colour for any bin that they add. Because I’d be rendering various graphics to the phone in the chosen colours I figured that the best way to persist the users choice was to store a SolidColorBrush. A small design decision made really early in the development of the app, it worked fine, the app got certified and is available now in the marketplace (subtle hint: go buy it
).
Now all the Mango goodness is available and it’s time to upgrade the Bin Day to take advantage of the new features available in the 7.5 update. Top of the requested features list is Live Tile support, so today I started in on supporting that feature. I’ve not tried Live Tile support in a 7.0 app, but by all accounts it was quite hard to set up local updates to the applications tile, Mango makes it a lot easier! However, this is where my off the cuff design decision from weeks before bit back.
Your Live Tile is updated locally by a ScheduledAgent, this is a separate project in your solution and is kicked off about every 30 minutes on the phone (if resources are available). The ScheduledAgent runs in a separate background thread, as mentioned my Bin Object stores the colour as a SolidColourBrush, newing up a SolidColorBrush needs the UI thread so when the agent tries to run it chokes with an Invalid cross-thread access error. Whilst you can dispatch to the UI thread because I was instancing the SolidColorBrush so deep in the code I figured I’d just change it all up and do it a different way. I’m now storing the colours in the database as a serialised argb string – a lot easier to deal with.