public void StartMoving() { this.stop = true; AsyncMove am = new AsyncMove(Move); am.BeginInvoke(new AsyncCallback(CallBackMove), am); }
public Form1() { redballs[0] = new Ball(new Point(0, 100), "Right", false, Brushes.Red); redballs[1] = new Ball(new Point(0, 300), "Right", false, Brushes.Red); blueballs[0] = new Ball(new Point(1085, 200), "Left", false, Brushes.Blue); blueballs[1] = new Ball(new Point(1085, 400), "Left", false, Brushes.Blue); DoubleBuffered = true; InitializeComponent(); AsyncMove am = CreateRedBallsEllipse; am.BeginInvoke(null, null); }
public void RightMove(object obj) { while (direction == "Right" && stop == true) { Thread.Sleep(100); position.X += 10; if (position.X >= 1090) { StopMove(); if (position.Y == 100) { Delegate[] delList = ChangeDirection.GetInvocationList(); // ассинхронное событие // и выполнить их асинхронно foreach (Delegate del in delList) { AsyncMove deleg = (AsyncMove)del; // Текущий делегат deleg.BeginInvoke(null, null); // Выполнить } } } } }