WP7 游戏:停用时调用 Web 服务(逻辑删除)

发布于 2024-10-29 14:35:38 字数 699 浏览 3 评论 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);
    }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末が日狂欢 2024-11-05 14:35:38

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

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

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

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.

淡看悲欢离合 2024-11-05 14:35:38

科学解释:

HttpWebRequest 是从 UI 线程分派的,因此如果您的应用/游戏 UI 线程在调用退出游戏后从未更新,则请求将永远不会发送。您可以通过创建一个 Web 请求然后循环直到请求完成(等待异步结果完成状态)来测试这一点 - 请求将永远不会被发送,您将永远等待。您可以尝试引入几百毫秒的延迟(不让 UI 线程进入睡眠状态,这仍然会阻止请求)并查看是否发出请求。在 XNA 中,这意味着对一些更新调用不执行任何操作来查看请求是否已发送。您还可以使用计时器。

致谢:dadoo Games http://forums.create.msdn.com/forums/ t/79737.aspx

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文