William B. Purvis patented the electric switch on railways that would shut off the electric supply after carriages pass the contact device.

Source