The most accurate way is to use an interrupt. Some ports can be configured to generate an interrupt on either edge. When the transition occurs, the program branches immediately to your interrupt handler.
Another way is to poll the input. This way you have a loop running that simply checks the state of the pin continuously and branches to your handler when the transition occurs. This may be difficult to get accurate timing if your program needs to do other things while waiting for the transition.
You can use a scheduler to spawn off a task that only monitors the input pin. You will need a RTOS or Scheduler running to do this - ie. commercial libraries. Then you can run another application that is virtually independently of the input monitor.