I create simple XNA fullscreen application. If it is active and the system goes into sleep mode or hibernate mode after resume the application is crashed. How can I solve this problem?
UPD: I added handler for system message
public Game()
{
SystemEvents.PowerModeChanged += OnPowerChange;
this.graphics.PreferredBackBufferWidth = 1920;
this.graphics.PreferredBackBufferHeight = 1080;
this.graphics.PreferredBackBufferFormat = SurfaceFormat.Bgr565;
this.graphics.IsFullScreen = true;
}
void OnPowerChange(Object sender, PowerModeChangedEventArgs e)
{
switch (e.Mode)
{
case PowerModes.Suspend:
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 600;
graphics.ToggleFullScreen();
graphics.ApplyChanges();
break;
}
}
If application is in window mode, then OnPowerChange() work fine and change resolusion from 1920x1080 to 800x600. But if application is fullscreen mode, then this method not called. Also, I get runtime error here
static void Main(string[] args)
{
using (Game game = new Game())
{
game.Run();
}
}
Error is: Cannot access a disposed object. Object name: 'WindowsGameForm'.