InvalidOperationException when setting track properties from a BackgroundAgent on Windows Phone

This is just a feature that I stumbled upon when I was updating my radio app I wanted to add an enhancement, so that when the radio was playing I wanted to display the current song on the lock screen (UVC). This should be very simple and just a matter of setting the information on the current track. So back in Visual Studio I wrote the following code: BackgroundAudioPlayer.Instance.Track.BeginEdit(); BackgroundAudioPlayer.Instance.Track.Artist = "Artist"; BackgroundAudioPlayer.Instance.Track.Title = "Title"; BackgroundAudioPlayer.Instance.Track.EndEdit(); And this all compiled fine enough. But when I started retesting my app, I got an InvalidOperationException, which seemed quite curious. After a bit of googling though I found the answer, which was actually quite simple. For some reason when you call BackgroundAudioPlayer.Instance.Track you do not always get the same object (at least not when doing it from a BackgroundAgent), so in effect that means, that when you call BeginEdit, you do that on one object, but then when you try setting the artist you get another object, which is not in edit mode and therefore the invalidoperation exception. Solving it was fairly easy and just required copying the current track to a local variable and working on it there, and then everything is running smoothly. So my code ended up like this and the problem was solved: var track = BackgroundAudioPlayer.Instance.Track; track.BeginEdit(); track.Artist = "Artist"; track.Title = "Title"; track.EndEdit();

Windows Phone 7 owner

Having recently participating in a competition to win a Windows Phone 7, I am now the proud owner of a HTC Surround running Windows Phone 7. So I’m going to add some blogposts about my experience, having posted the first one already. In case the competition link/description goes offline I can tell the reason for me winning was the fact that I submitted 3 apps to the Danish Windows Phone Marketplace, which are the following Simply Math Dagsordener Nationalfilmografien Feel free to check them out and comment on them

Moving from iPhone to Windows Phone

Since I just received a HTC Surround running Windows Phone 7, I thought I would like to share some of my experiences making the switch from an iPhone to this new phone. To begin with I can say that I have been using first an iPhone 3GS and then an iPhone 4 for about 3-4 years, so I was pretty accustomed to the iPhone. The upgrade from 3GS to 4 went without any trouble using an iTunes backup. Unfortunately that scenario was ruled out switching to a Windows Phone. So some things had to be considered. I have been moving many things into the cloud lately, so a lot of things would be simple to move. Some of the easy (with some magic involved) items were My private email running off gmail using IMAP My work email running of an exchange server My notes in Evernote My books in Amazon Kindle My private contacts (synchronized with a local Outlook through Windows Live – had to go the csv path) Off course I am now bound to find some alternative apps/games for all the rest, but at least I got the basics covered. One thing I was missing though was my stream of text messages. I like to keep a history so off course I would like to get my text messages with me to on the new phone. But from looking at the internet a bit I couldn’t seem to find any clear path for this. So what to do? Well first things first. I made a backup of my iPhone. This produced a lot of backup files and in particular it created a file named C:\Users\[USERNAME]\AppData\Roaming\Apple Computer\MobileSync\Backup\[DEVICE SPECIFIC GUID]\3d0d7e5fb2ce288813306e4d4636395e047a3d28 This file turns out to be an sqlite database containing my messages… yipee, so I have my messages, but then what… And that is my current status… So I have my message history and is now waiting for Microsoft to open up for an SMS API, so that I can have them restored onto my new phone.