Till the caps fail? So 20-30 years +. I've got TMCC stuff from 1995-1997 that still works fine, and MTH PS2 3V stuff from 2004 that works great as well. The less shorts you have the better. Current spikes can kill electronics pretty quickly. I've never had something I haven't run in months just die from being operated (well yet, knock on wood).
FYI: The MTH PS2 models that tend to spontaneously fail are the PS2 5V boards from 2000-2003/2004ish. The PS2 3V stuff from 2004 up has been pretty rock solid. PS2 5V boards were built around the time of the "Capacitor Plague": https://en.wikipedia.org/wiki/Capacitor_plague I've seen several PS2 5V boards killed by blown capacitors. I've also seen several TAS EOB boards built in the early 2000s where the motor FETs died and took out the whole board (burned up traces).
Before someone chimes in on the durability of prewar or postwar trains: if you remove the electronics from a modern locomotive it is more mechanically robust than pretty much 60+ year old train. If modern locomotives came with a mechanical E-unit they would run and run virtually forever with no maintenance (i.e. no need to clean commutators or replace brushes/brush springs).