diff --git a/CustomDevice/DeviceGraphics.cs b/CustomDevice/DeviceGraphics.cs index 668db73..879db31 100644 --- a/CustomDevice/DeviceGraphics.cs +++ b/CustomDevice/DeviceGraphics.cs @@ -60,6 +60,11 @@ } } + public static bool Exited { + get; + internal set; + } + private static Graphics GetScreen_InterNet2() { // In the InterNet2 System.Drawing dll Graphics.FromHdc() will always // return the Graphics object for the screen. diff --git a/CustomDevice/WindowsScreen.cs b/CustomDevice/WindowsScreen.cs index 7f23284..8300343 100644 --- a/CustomDevice/WindowsScreen.cs +++ b/CustomDevice/WindowsScreen.cs @@ -53,6 +53,7 @@ this.ClientSize = new Size(width, height); + this.Closed += (sender, args) => DeviceGraphics.Exited = true; this.Show(); this.Activate(); @@ -74,7 +75,7 @@ internal static void WindowsMessagePump(object state) { WindowsScreen.winScreen = new WindowsScreen(DeviceGraphics.ScreenXSize, DeviceGraphics.ScreenYSize); - for (; ; ) { + for (; !DeviceGraphics.Exited; ) { Application.DoEvents(); Thread.Sleep(40); WindowsScreen.winScreen.Refresh(); diff --git a/Snake/Program.cs b/Snake/Program.cs index 6144a8f..596f79f 100644 --- a/Snake/Program.cs +++ b/Snake/Program.cs @@ -47,6 +47,10 @@ CrashType crashType; for (; ; ) { + + if (DeviceGraphics.Exited) + return false; + Thread.Sleep(delay); KeyPadKey key; if (KeyPad.LatestKeyDown(out key)) {