Spectral series of the Schrödinger operator in a thin waveguide with a periodic structure. 2. Closed three-dimensional waveguide in a magnetic field