public static GraphicsDeviceService AddReference(IntPtr windowHandle, int width, int height)
 {
     if (Interlocked.Increment(ref referenceCount) == 1)
     {
         instance = new GraphicsDeviceService(windowHandle, width, height);
     }
     return instance;
 }
        protected override void Dispose(bool disposing)
        {
            if (service != null)
            {
                service.Release(disposing);
                service = null;

                if (gameLoopThread != null && gameLoopThread.IsAlive)
                {
                    gameLoopThread.Abort();
                }
            }
            base.Dispose(disposing);
        }
        protected override void OnCreateControl()
        {
            if (!DesignMode)
            {
                service = GraphicsDeviceService.AddReference(
                    Handle,
                    ClientSize.Width,
                    ClientSize.Height);

                service.DeviceReset += onDeviceReset;
                Services.AddService<IGraphicsDeviceService>(service);

                if (GameLoopEnabled)
                {
                    gameLoopThread = new Thread(gameLoop);
                    gameLoopThread.IsBackground = true;
                    gameLoopThread.Priority = ThreadPriority.Normal;

                    gameLoopThread.Start();
                }
                else
                {
                    LoadContent();
                }
            }
            base.OnCreateControl();
        }