void StopMotorWithEncoderHandler(encoder.EncoderOperations encoderNotificationPort, encoder.UpdateTickCount msg, Motor.MotorOperations motorPort, int stopWheelAt) { if (msg.Body.Count >= stopWheelAt) { Motor.SetMotorPower stop = new Motor.SetMotorPower(0); motorPort.Post(stop); Arbiter.Choice(stop.ResponsePort, delegate(DefaultUpdateResponseType resp) { }, delegate(Fault fault) { LogError(fault); } ); } else { // Call self to continue waiting for notifications Activate(Arbiter.Receive<encoder.UpdateTickCount>(false, encoderNotificationPort, delegate(encoder.UpdateTickCount update) { StopMotorWithEncoderHandler(encoderNotificationPort, update, motorPort, stopWheelAt); } )); } }