  The problem of defining work done on electromagnetic field (EMF) via moving
charges does not have a ready solution, because the standard Hamiltonian of EMF
does not predict gauge-invariant energy changes. This limits applications of
statistical mechanics to EMF. We obtained a new, explicitly gauge-invariant
Hamiltonian for EMF that depends only on physical observables. This Hamiltonian
allows to define thermodynamic work done on EMF and to formulate the second law
for the considered situation. It also leads to a direct link between this law
and the electrodynamic arrow of time, i.e. choosing retarded, and not advanced
solutions of wave-equations. Measuring the thermodynamic work can give
information on whether the photon mass is small but non-zero.
