3

I noticed that, if in WP7 application I press Start key then quickly Back key to return to the app, and very quickly repeat these steps many times, the application ends up being crashed (it exits unexpectedly and no way to recover it via Back key). This happens on device (never seen on emulator), and it takes 10-15 steps before the application gets shut down. I follow Microsoft guidelines about saving / restoring its state. Furthermore, all other apps I've tried in such way crash too. However, some apps are much harder to kill in this way than the others. During experiments with this stress test, I noticed that

  • XNA games tend to be less resistant than pure Silverlight apps
  • The more data the application saves / recovers, the less resistant it is
Unfortunately, my XNA game has to save a lot of data during deactivation, and it's pretty easy to get it crashed.

Does anyone know if it's a known problem or something else? I'd appreciate any advice of how to make the game more stable if it's not possible to completely eliminate the problem.

4

2 回答 2

1

关于问题可能存在于反序列化过程中的想法,您可以这样做:

    private IsolatedStorageSettings isosettings = IsolatedStorageSettings.ApplicationSettings;
    void Application_deactivated()
    {
        isosettings.Add("serialization_finished", false);//just add once, 
                    //after that use isosettings["serialization_finished"]
        //DO: save here your code into isostorage
        isosettings["serialization_finished"] = true;
    }
    void Application_activated()
    {
        while (!isosettings["serialization_finished"])
            Thread.Sleep(500);
        //DO: read you data from isostorage
    }

因此,您实际上构建了一个开/关开关来测试序列化过程是否完成

老的:

墓碑有一个他必须完成的时间限制(10 秒)。我的猜测是你给了他太多的墓碑,以至于在某一时刻应用程序的一个实例无法及时完成墓碑。但这只是一个假设,前提是要保存的越多=崩溃的速度越快。

您可以通过测量墓碑化所需的时间并将数据写入隔离存储来测试这一点。当您分析数据并看到墓碑时间增加(最多 8-9 秒)时,您可以得出结论,它应该是时间。

另一方面,如果所需时间从未增加并停留在几秒钟内,您可以放心地得出结论,这不应该是一个时间问题

于 2012-04-03T12:42:37.247 回答
1

我找到了一种解决方法,如何使应用程序更加稳定。实际上,我们不想在每次停用期间都将游戏数据保存到隔离存储中。只有在游戏状态发生变化时才需要。由于我的游戏在激活后会自动暂停,所以它的状态没有改变,我不必再次保存它的数据,直到用户恢复游戏。因此,仅在第一次停用时才将数据存储到隔离存储中。这种方法有一点帮助,但不是太多。开始键/返回键的 20 次迭代仍然使其下降。

于 2012-04-04T06:01:46.713 回答