Make sure you are creating an optimized caml query to avoid threshold limits. This can be done by using indexed fields in your where clauses. Another possible optimization is to order or sort by an indexed field. You can force this by always sorting by the ID field using the following:
<OrderBy Override='TRUE'><FieldRef Name='ID' /></OrderBy>
You can also query in batches to avoid the limit. The PowerShell example in the link below uses a row limit of 2000 and the ListItemCollectionPosition: http://blogs.msdn.com/b/kaevans/archive/2012/02/13/iterating-large-sharepoint-lists-with-powershell.aspx
Inspired by forum discussion: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/18802ebb-d9b6-44ad-a58b-e7c4810502fd