开发者

Is it possible to send an HttpWebRequest from a deactivated event handler in WP7?

开发者 https://www.devze.com 2023-03-28 07:34 出处:网络
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 l

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 cod开发者_如何学编程e using sockets or did I just misunderstand something?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消