How does it deal with times when multiple programs are open?

At any given time the user can in fact work with only a single program.
The StaffCounter application defines an active program and counts time in it. When the user switches from program A to program B, StaffCounter registers an end to the working session in program A and begins a new working session in program B. Each session is counted separately in the log. Thus, the time spent working in an application is totaled from all sessions logged for this application.