The game freezes while saving.

May 3, 2012 at 9:36 PM

When I use this to save my game on the XBOX360 it freezes up for about .75-1 seconds.  I'm wondering if I'm doing something wrong.  The saving and loading works, but it's pretty slow.

First off I make a thread to run it.  I originally didn't have a thread but I'd hoped this would make it not lock things up.  It doesn't seem to have made a difference.

 

Thread SaveThread = new Thread(SaveGame);
SaveThread.IsBackground = true;
SaveThread.Start();

 

Here is the SaveGame function.

        private static void SaveGame()
        {
            try
            {
                // make sure the device is ready
                if (SaveDevice.IsReady)
                {
                    // save a file asynchronously. this will trigger IsBusy to return true
                    // for the duration of the save process.
                    SaveDevice.SaveAsync(
                        containerName,
                        fileName_data,
                        stream =>
                        {
                            try
                            {
                                XmlSerializer serializer = new XmlSerializer(typeof(SaveData));
                                serializer.Serialize(stream, saveData);
                            }
                            catch (Exception) { }
                        });
                }
            }
            catch (Exception) { }
        }  

Any ideas as to how I can make this not lock the game up whenever I need to save things?  Thank you for reading.