Question

In a networked XNA WP7 game, I want to notify the server when the game gets deactivated, e.g., when I press the search button during the game. The game uses HTTP requests for networking and it seems like HttpWebRequests do not get handled immediately but at some point in the main loop in the UI thread. In other words, any HttpWebRequest I make from a deactivated event handler just before the app gets tombstoned will never get handled.

Is there a workaround for this without having to rewrite the whole networking code using sockets or did I just misunderstand something?

Was it helpful?

Solution

The deactivated event is intended to be used to store application state as the application is deactivated (and possibly tombstoned). This event was never intended to be used to make web requests. Note that if you do try and make a request in this event, just because a response isn't received by the app doesn't mean that it doesn't get to the server though.

In that it's a networked game I'm assuming that you need to be online to play. If that's the case what happens if the device loses a network connection? Surely you'd be in just the same situation but you certainly couldn't send a notification to the server.
I suspect you need to think about your application model differently.

If you really need to be online to play could you not have the server just assume that the connection is lost if it doesn't hear from a device for a ertain period of time

Depending on the game you may also need to consider caching any game state/actions if the connection drops only briefly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top