是否可以从 WP7 中停用的事件处理程序发送 HttpWebRequest?
在联网的 XNA WP7 游戏中,我想在游戏停用时通知服务器,例如,当我在游戏过程中按下搜索按钮时。该游戏使用 HTTP 请求进行网络连接,并且 HttpWebRequest 似乎不会立即得到处理,而是在 UI 线程的主循环中的某个时刻得到处理。换句话说,在应用程序被逻辑删除之前,我从已停用的事件处理程序发出的任何 HttpWebRequest 将永远不会得到处理。
是否有解决方法,而不必使用套接字重写整个网络代码,或者我只是误解了什么?
In a networked XNA WP7 game, I want to notify the server when the game gets deactivated, e.g., when I press the search button during the game. The game uses HTTP requests for networking and it seems like HttpWebRequests do not get handled immediately but at some point in the main loop in the UI thread. In other words, any HttpWebRequest I make from a deactivated event handler just before the app gets tombstoned will never get handled.
Is there a workaround for this without having to rewrite the whole networking code using sockets or did I just misunderstand something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
停用事件旨在用于在应用程序被停用(并且可能被逻辑删除)时存储应用程序状态。此事件从未打算用于发出 Web 请求。请注意,如果您尝试在此事件中发出请求,仅仅因为应用程序未收到响应并不意味着它不会到达服务器。
因为这是一款网络游戏,我假设您需要在线才能玩。如果是这种情况,如果设备失去网络连接会发生什么?当然,您也会遇到同样的情况,但您肯定无法向服务器发送通知。
我怀疑您需要以不同的方式考虑您的应用程序模型。
如果您确实需要在线玩游戏,您是否可以让服务器在一段时间内没有收到设备的消息时假设连接丢失,
具体取决于游戏,您可能还需要考虑缓存任何游戏如果连接只是短暂断开,则状态/操作。
The deactivated event is intended to be used to store application state as the application is deactivated (and possibly tombstoned). This event was never intended to be used to make web requests. Note that if you do try and make a request in this event, just because a response isn't received by the app doesn't mean that it doesn't get to the server though.
In that it's a networked game I'm assuming that you need to be online to play. If that's the case what happens if the device loses a network connection? Surely you'd be in just the same situation but you certainly couldn't send a notification to the server.
I suspect you need to think about your application model differently.
If you really need to be online to play could you not have the server just assume that the connection is lost if it doesn't hear from a device for a ertain period of time
Depending on the game you may also need to consider caching any game state/actions if the connection drops only briefly.