开发者

WP7 game: Call Web Service when Deactivated (tombstoning)

开发者 https://www.devze.com 2023-02-22 13:00 出处:网络
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 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()
    {
        _开发者_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

0

精彩评论

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

关注公众号