Declaring variables as static retains the variable value after the procedure containing the variable ends. See http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

How and where is the variable pageCounter being declared?