Canguro.Controller.CommandServices.wait C# (CSharp) Method

wait() private method

Method that locks commands when waiting for user interaction, until the requested action has been performed. For example, if a command requests for a Joint, then it gets locked until the user picks one by any means available.
private wait ( WaitingFor waitingFor, bool startSelection ) : void
waitingFor WaitingFor The object that was picked by the user
startSelection bool The type of object that the command requests (i.e. Joint, Line, Point, etc.)
return void
        private void wait(WaitingFor waitingFor, bool startSelection)
        {
            Commands.ModelCommand mc;
            selectionFilter = waitingFor;

            if (startSelection)
                controller.SelectionCommand.Start(this);

            while (selectionFilter != WaitingFor.None)
            {
                // if ModelCmd has been cancelled or ModelCmd is no longer registered on the Controller
                // Cancel the command and stop the waiting
                if (((mc = controller.ModelCommand) == null) || ((mc != null) && (mc.Cancel)))
                    throw new CancelCommandException();

                // Para evitar que este ciclo se coma todo el cpu, porque
                // DoEvents sólo pasa el control al MessageLoop de la aplicación
                // para que cheque si hay mensajes y en caso contrario regresa
                // inmediatamente, lo que hace que este ciclo se convierta en un
                // while que consume el 100% del cpu nomás por esperar
                // (Exactamente como el PropertyGrid cuando despliega un DropDown)
                // La llamada a la rutina de abajo duerme al hilo hasta que ocurra
                // cualquier evento, con lo que se arregla el problema
                Canguro.Utility.NativeHelperMethods.WaitInMainThread(250);
            }
        }