public static void InvokeMethod(this Form form, FormInvoker invoker) { if (form.IsDisposed) { return; } try { if (form.InvokeRequired) { form.Invoke(new MethodInvoker(invoker)); } else { invoker.Invoke(); } } catch (ThreadAbortException) { // ignore } catch (ObjectDisposedException) { // ignore } }
private void Render() { Bitmap bitmap = new Bitmap(GameField.SizeField.Width, GameField.SizeField.Height); Graphics graphics = Graphics.FromImage(bitmap); KolobokView.Kolobok.Render(GameField.Kolobok, graphics); foreach (Wall wall in GameField.walls) { WallView.Wall.Render(wall, graphics); } foreach (Apple apple in GameField.apples) { AppleView.Apple.Render(apple, graphics); } foreach (Tank tank in GameField.tanks) { TankView.Tank.Render(tank, graphics); } foreach (River river in GameField.rivers) { RiverView.River.Render(river, graphics); } foreach (FragileBlock fragileBlock in GameField.fragileBlocks) { FragileBlockView.FragileBlock.Render(fragileBlock, graphics); } foreach (Bullet bullet in GameField.bullets) { BulletView.Bullet.Render(bullet, graphics); } foreach (Bullet bullet in GameField.enemyBullets) { BulletView.Bullet.Render(bullet, graphics); } FormInvoker fi = delegate { pictureBox1.Image = bitmap; pictureBox1.Invalidate(); }; Invoke(fi); }