XNA добавить сон, когда окно не в фокусе!
Я решил эту проблему некоторое время назад, изменив класс Game и изменив способ, которым класс Game понимает, активна его форма или нет.
Насколько я знаю, нет способа отключить это поведение без изменения поведения класса Game с помощью кода.
В частности, способ, который я нашел некоторое время назад, это настоящий хак \ quirk!
Очень грязное решение, но единственный способ, который я нашел.
public class MyGame
{
private MethodInfo pActivate;
public MyGame()
{
// We need to access base HostActivate method, that unfortunally, is private!
// We need to use reflection then, of course this method is an hack and not a real solution!
// Ask Microsoft for a better implementation of their class!
this.pActivate = typeof(Game).GetMethod("HostActivated", BindingFlags.NonPublic | BindingFlags.Instance);
}
protected sealed override void OnDeactivated(object sender, EventArgs args)
{
base.OnDeactivated(sender, args);
// Ok, the game form was deactivated, we need to make it believe the form was activated just after deactivation.
if (!base.Active)
{
// Force activation by calling base.HostActivate private methods.
this.pActivate.Invoke(this, new object[] { sender, args });
}
}
}