Search code examples
wcfweb-serviceswindows-phone-7xnatombstoning

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 :

  1. I'm developping a multiplayer game in XNA for WP7
  2. When a user quits the game (enters in tombstoning or exiting), I want to warn others players that a player left
  3. I override the Game.OnExiting() method to call my Web Service, and I have put a breakpoint on this line
  4. 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()
    {
        _client.QuitGameAsync(GameManager.Instance.GameId, _myRank);
    }

Solution

  • 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