I think the reason the P-40 was used for so long is there was a shortage of fighters. They couldn't build enough of them and it made more sense to continue to produce models already in production as long as they weren't completely obsolete. As a result the P-40 remained in production for most of the war I believe. After the early stages of the war it was relagated to "minor" or "backwater" theaters of the war like Africa and the South Pacific. In addition, many allies of the US were screaming for fighters and were given the less desireable P-40's. Austrailia and New Zealand flew P-40's till the end of the war, and quite effectively.