In a magnetic field, vortices significantly contribute to the dark counts of single-photon detectors made of superconducting wires, and they are also limiting the critical current of such devices. To address this issue, we prepared superconducting microwires with a pinhole grid from WSi thin films and report on corresponding critical-current and count-rate measurements in an external magnetic field B. When compared to corresponding devices without pinholes, the critical current only weakly depends on the magnetic field at B < 16 mT and it is even larger already at B > 10 mT. Moreover, dark counts are not only suppressed in zero field, but particularly in magnetic fields B < 16 mT, while photon counts are virtually field insensitive in the same range of the magnetic field.