WP7 game: Call Web Service when Deactivated (tombstoning)
I'm running into a weird problem and I want to know if it is normal or if I'm missing something.
Here's the situation :
- I'm developping a multiplayer game in XNA for WP7
- When a user quits the game (enters in tombstoning or exiting), I want to warn others players that a player left
- I override the
Game.OnExiting()
method to call my Web Service, and I have put a breakpoint on this line - Each time, the breakpoint gets hit, the call is made, no error occurs, but the server never receives the call
Is it normal that the call is not processed on the server because the game is exiting?
Here's the code :
protected override void OnExiting(object sender, EventArgs args)
{
if (GameManager.Instance.IsOnlineGame && !Guide.IsVisible)
{
GameManager.Instance.Multiplayer.QuitGame();
}
base.OnExiting(sender, args);
}
internal void QuitGame()
{
_开发者_StackOverflow社区client.QuitGameAsync(GameManager.Instance.GameId, _myRank);
}
Your app only has a very short time to perform any operations when exiting. Calling a web service has the potential to take longer than may be permitted to you.
It's not clear from the amount of code you have posted what resources are available to make the call (and pass necessary data) either.
If you do do this you shouldn't rely on that message being sent to the server. This may have implications for your applicaiton logic.
Scientific explanations:
HttpWebRequests are dispatched from the UI thread so if your app/game UI thread never updates after your call to quit the game the request will never be sent. You can test this by creating a web request and then looping until the request is completed (waiting on the async result complete state) - the request will never be sent and you will wait forever. You could try introducing a delay of a few hundred milliseconds (without putting the UI thread to sleep which would still block the request) and see if the request is made. In XNA this would mean doing nothing for a few update calls to see if the request is sent. You could also use a timer.
Credits : dadoo Games on http://forums.create.msdn.com/forums/t/79737.aspx
精彩评论