I followed the advice on msdn about how to add a buy now button to my Windows phone app.
Today, I noticed I had a crash in one of our applications, and downloaded the stack trace.
On the stack is MarketplaceDetailTask.Show
A bit of searching and trial and error shows that if the user executes this quickly (by double tapping the button the handler is on) the program will crash.
I’m guessing the user didn’t buy.
To solve this, I added the following belt and braces code:
private void OnPurchase(object sender, RoutedEventArgs e)
btnbuynow.IsEnabled = false;
catch (InvalidOperationException ex)
This disables the button which prevents subsequent button presses while transitioning. I catch the exception thrown for good measure, though as no type of exception is documented to be raised, maybe I should just catch everything.
I then reenable the buy now button whenever the page is navigated to as follows:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
btnbuynow.IsEnabled = true;