XNA は、ウィンドウがフォーカスされていないときにスリープを追加します! Game クラスをオーバーライドし、Game クラスがそのフォームがアクティブかどうかを理解する方法を変更する前に、この問題を解決しました。
私の知る限り、Game クラスの動作をコードで変更せずにこの動作を無効にする方法はありません。
特に、私が少し前に見つけた方法は、本当のハック\クワックです! 非常に汚れた解決策ですが、私が見つけた唯一の方法です。
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 });
}
}
}