Пример #1
0
        public static void HomeAndWait(this IMotor mtr)
        {
            // sync used to wait for move in first axis before proceeding to second axis
            object sync = new object();
            // flag to avoid deadlock in case notify() is called before before the sync-block after each Move()
            bool move_completed = false;
            StrongTypedEventHandler <IMotor, MoveCompletedArgs> notify =
                (motor, args) => { lock (sync) { move_completed = true;  Monitor.Pulse(sync); } };

            mtr.MoveCompleted += notify;
            try
            {
                mtr.Home();
                lock (sync) { if (!move_completed)
                              {
                                  Monitor.Wait(sync);
                              }
                }
            }
            finally
            {
                mtr.MoveCompleted -= notify;
            }
        }