The game save the data in OnApplicationPause event. It takes about 2 seconds to sarialize and to save the data. If I kill the game process in a task manager while the data is saving, the save file will be incorrect. And the game progress will be lost. I save data like this: Code (CSharp): public virtual void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(FileName(), FileMode.OpenOrCreate, FileAccess.Write); bf.Serialize(file, this); file.Close(); } Can I lock the game in a memory while the data is saving? Or can I save data faster?
You can't prevent someone from killing off the game on their own. If someone chooses to end it, that is their choice. This is the purpose of being able to kill things off (You see this in games all the time, don't close the game while the saving indicator is up) If your data is taking a long time to save, you either need to offer them another way to save or look at how much data you are saving and see if there is a way to cut down on the data. Or, you could save at different points in the game and use a saving indicator.