Except, the law doesn't just prohibit carrying a firearm in a school when classes are in session. It specifically prohibits:
B. If any person possesses any firearm designed or intended to expel a projectile by action of an explosion of a combustible material while such person is upon (i) any public, private or religious elementary, middle or high school, including buildings and grounds; (ii) that portion of any property open to the public and then exclusively used for school-sponsored functions or extracurricular activities while such functions or activities are taking place; or (iii) any school bus owned or operated by any such school, he shall be guilty of a Class 6 felony.
The wording here makes it clear that it isn't just referring to the school as a gathering of people in an educational setting (as would apply in (ii)), but also the physical building and grounds commonly used for that purpose, or the organization that provides such services (and any property that said organization owns or uses for that purpose).
Even if part of the building is being used as a polling place, it is still part of the "buildings and grounds" of a "public, private or religious elementary, middle or high school", and so carry would be prohibited.