0

我遇到了一个奇怪的问题,我想知道它是否正常,或者我是否遗漏了什么。

情况如下:

  1. 我正在 XNA 中为 WP7 开发多人游戏
  2. 当用户退出游戏(进入墓碑或退出)时,我想警告其他玩家有玩家离开
  3. 我重写了Game.OnExiting()调用我的 Web 服务的方法,并且我在这一行上放了一个断点
  4. 每次,断点被命中,调用,没有发生错误,但服务器从来没有收到调用

由于游戏退出,调用没有在服务器上处理是正常的吗?

这是代码:

    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);
    }
4

2 回答 2

3

您的应用在退出时只有很短的时间来执行任何操作。调用 Web 服务可能需要比您允许的时间更长的时间。

从您发布的代码量中也不清楚哪些资源可用于进行调用(并传递必要的数据)。

如果你这样做,你不应该依赖发送到服务器的消息。这可能对您的应用程序逻辑有影响。

于 2011-04-04T16:30:47.883 回答
0

科学解释:

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

于 2011-04-04T20:48:21.850 回答